Skip to content

Commit

Permalink
Merge pull request #21 from quillcraftsman/models
Browse files Browse the repository at this point in the history
Models
  • Loading branch information
quillcraftsman authored Mar 6, 2024
2 parents 7e55f55 + 59a9edb commit 108550e
Show file tree
Hide file tree
Showing 30 changed files with 653 additions and 283 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ package_docs:
sphinx-apidoc -o docs/package replay_wizard/

capture:
python main.py capture debug
python capture.py debug

time_capture:
python main.py capture debug -t true
python capture.py debug -t true

replay:
python main.py replay debug -d 5
python replay.py debug -d 5

time_replay:
python main.py replay debug -t true -d 5
python replay.py debug -t true -d 5

monitor_replay:
python main.py replay debug -t true -d 5 -m true
python replay.py debug -t true -d 5 -m true

capture_mouse:
python main.py capture debug -k false -mo true -t true
python capture.py debug -k false -mo true -t true

capture_all:
python main.py capture debug -mo true -t true
python capture.py debug -mo true -t true
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,19 @@ See more in [Full Documentation](https://replaywizard.craftsman.lol/install.html
### Capture Sequence

```commandline
replay-wizard capture openyoutube
wizard-capture openyoutube
```

### Replay Sequence

```commandline
replay-wizard replay openyoutube -d 10
wizard-replay openyoutube -d 10
```

### Combine Sequences

```commandline
wizard-combine three one two
```

### More examples in [Full Documentation][documentation_path]
Expand Down Expand Up @@ -140,6 +146,7 @@ This features will be built during 4 weeks.
- Replay environment
- Console script (Done)
- python library API (Done)
- Combine sequences (Done)

## Requirements

Expand Down
8 changes: 8 additions & 0 deletions capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Manual run module
"""
from replay_wizard.__main__ import capture


if __name__ == '__main__':
capture()
8 changes: 8 additions & 0 deletions combine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Manual run module
"""
from replay_wizard.__main__ import combine


if __name__ == '__main__':
combine()
1 change: 1 addition & 0 deletions docs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This features will be built during 4 weeks.
- Replay environment
- Console script (Done)
- python library API (Done)
- Combine sequences (Done)

Requirements
------------
Expand Down
11 changes: 9 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ To capture actions

.. code-block:: bash
replay-wizard capture openyoutube
wizard-capture openyoutube
To replay actions
=================

.. code-block:: bash
replay-wizard replay openyoutube -d 10
wizard-replay openyoutube -d 10
To combine sequences
=================

.. code-block:: bash
wizard-combine three one two
Using python
^^^^^^^^^^^^
Expand Down
15 changes: 0 additions & 15 deletions main.py

This file was deleted.

8 changes: 8 additions & 0 deletions replay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Manual run module
"""
from replay_wizard.__main__ import replay


if __name__ == '__main__':
replay()
22 changes: 16 additions & 6 deletions replay_wizard/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
"""
Package console entrypoint
"""
from replay_wizard.cli.app import run_cli
from replay_wizard.cli import capture_cli, replay_cli, combine_cli


def main():
def capture():
"""
main function to run CLI for package
capture CLI
"""
run_cli()
capture_cli()


if __name__ == "__main__":
main()
def replay():
"""
replay CLI
"""
replay_cli()


def combine():
"""
combine CLI
"""
combine_cli()
6 changes: 6 additions & 0 deletions replay_wizard/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
CLI package
"""
from .replay import replay_cli
from .capture import capture_cli
from .combine import combine_cli
75 changes: 0 additions & 75 deletions replay_wizard/cli/app.py

This file was deleted.

29 changes: 29 additions & 0 deletions replay_wizard/cli/capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
App CLI module
"""
import time
from replay_wizard import capture
from replay_wizard.storage import save_to_file
from .parser import get_parser, add_arguments


def capture_cli():
"""
Run capture CLI wizard-capture
"""

parser = get_parser('wizard-capture')
parser = add_arguments(parser)

args = parser.parse_args()

sequence_name = args.sequence
delay = args.delay
timedelta = args.timedelta
keyboard = args.keyboard
mouse = args.mouse

time.sleep(delay)

sequence = capture(sequence_name, timedelta, keyboard=keyboard, mouse=mouse)
save_to_file(sequence)
29 changes: 29 additions & 0 deletions replay_wizard/cli/combine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Combine CLI
"""
from replay_wizard.models import get_sequence
from replay_wizard.storage import load_from_file, save_to_file
from .parser import get_parser


def combine_cli():
"""
Combine CLI function
"""

parser = get_parser('wizard-combine')
parser.add_argument('sequences', nargs='+')
args = parser.parse_args()

sequence_name = args.sequence
sequence_names = args.sequences
true_time = args.timedelta

sequences = []
for name in sequence_names:
sequence = load_from_file(name, true_time=true_time)
sequences.append(sequence)

sequence_cls = get_sequence(true_time)
new_sequence = sequence_cls.combine(sequence_name, *sequences)
save_to_file(new_sequence)
48 changes: 48 additions & 0 deletions replay_wizard/cli/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Parser module
"""
import argparse

PROGRAM_DESCRIPTION = """
ReplayWizard is a powerful automation tool designed to streamline your workflow by capturing
and replaying your interactions with your computer
"""


def str2bool(v):
"""
Console bool parameter to bool python value
"""
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
if v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
raise argparse.ArgumentTypeError('Boolean value expected.')


def get_parser(command_name):
"""
Get argument parser
"""
parser = argparse.ArgumentParser(
prog=command_name,
description=PROGRAM_DESCRIPTION,
epilog=f'Use {command_name} -h to get help'
)

parser.add_argument('sequence')
parser.add_argument('-t', '--timedelta', default=False, type=str2bool)

return parser


def add_arguments(parser):
"""
Add same arguments
"""
parser.add_argument('-d', '--delay', default=0, type=int)
parser.add_argument('-k', '--keyboard', default=True, type=str2bool)
parser.add_argument('-mo', '--mouse', default=False, type=str2bool)
return parser
Loading

0 comments on commit 108550e

Please sign in to comment.