Skip to content

Commit

Permalink
Merge pull request #47 from JE-Chen/dev
Browse files Browse the repository at this point in the history
update stable and dev
  • Loading branch information
JE-Chen authored Jul 17, 2022
2 parents bc9da74 + 3c833c9 commit d557b12
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 32 deletions.
29 changes: 17 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 31 additions & 16 deletions je_auto_control/__main__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
# argparse
import argparse
import json
import sys

from je_auto_control.utils.exception.exception_tag import argparse_get_wrong_data
from je_auto_control.utils.exception.exceptions import AutoControlArgparseException
from je_auto_control.utils.json.json_file import read_action_json
from je_auto_control.utils.file_process.get_dir_file_list import get_dir_files_as_list
from je_auto_control.utils.executor.action_executor import execute_action
from je_auto_control.utils.executor.action_executor import execute_files

if __name__ == "__main__":
def preprocess_execute_action(file_path: str):
execute_action(read_action_json(file_path))
try:
def preprocess_execute_action(file_path: str):
execute_action(read_action_json(file_path))


def preprocess_execute_files(file_path: str):
execute_files(get_dir_files_as_list(file_path))
def preprocess_execute_files(file_path: str):
execute_files(get_dir_files_as_list(file_path))

def preprocess_read_str_execute_action(execute_str: str):
execute_str = json.loads(execute_str)
execute_action(execute_str)

argparse_event_dict = {
"execute_file": preprocess_execute_action,
"execute_dir": preprocess_execute_files
}
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--execute_file", type=str, help="choose action file to execute")
parser.add_argument("-d", "--execute_dir", type=str, help="choose dir include action file to execute")
args = parser.parse_args()
args = vars(args)
for key, value in args.items():
if value is not None:
argparse_event_dict.get(key)(value)
argparse_event_dict = {
"execute_file": preprocess_execute_action,
"execute_dir": preprocess_execute_files,
"execute_str": preprocess_read_str_execute_action
}
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--execute_file", type=str, help="choose action file to execute")
parser.add_argument("-d", "--execute_dir", type=str, help="choose dir include action file to execute")
parser.add_argument("--execute_str", type=str, help="execute json str")
args = parser.parse_args()
args = vars(args)
for key, value in args.items():
if value is not None:
argparse_event_dict.get(key)(value)
if all(value is None for value in args.values()):
raise AutoControlArgparseException(argparse_get_wrong_data)
except Exception as error:
print(repr(error), file=sys.stderr)
sys.exit(1)

4 changes: 4 additions & 0 deletions je_auto_control/utils/exception/exception_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
html_generate_no_data_tag = "record is None"
# add command
add_command_exception_tag = "command value type should be as method or function"
# executor
executor_list_error = "executor receive wrong data list is none or wrong type"
# argparse
argparse_get_wrong_data = "argparse receive wrong data"
4 changes: 4 additions & 0 deletions je_auto_control/utils/exception/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ class AutoControlAddCommandException(AutoControlException):
pass


class AutoControlArgparseException(AutoControlException):
pass


13 changes: 9 additions & 4 deletions je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from je_auto_control import mouse_table, check_key_is_press, position, press_mouse, release_mouse, click_mouse, scroll
from je_auto_control import set_position
from je_auto_control import screenshot, size, special_table
from je_auto_control.utils.exception.exception_tag import action_is_null_error, add_command_exception_tag
from je_auto_control.utils.exception.exception_tag import action_is_null_error, add_command_exception_tag, \
executor_list_error
from je_auto_control.utils.exception.exception_tag import cant_execute_action_error
from je_auto_control.utils.exception.exceptions import AutoControlActionException, AutoControlAddCommandException
from je_auto_control.utils.exception.exceptions import AutoControlActionNullException
Expand Down Expand Up @@ -59,15 +60,18 @@ def _execute_event(self, action: list):
elif len(action) == 1:
event()
else:
raise AutoControlActionException(cant_execute_action_error)
raise AutoControlActionException(cant_execute_action_error + " " + str(action))

def execute_action(self, action_list: list) -> dict:
def execute_action(self, action_list: [list, dict]) -> dict:
"""
use to execute all action on action list(action file or program list)
:param action_list the list include action
for loop the list and execute action
"""

if type(action_list) is dict:
action_list = action_list.get("web_runner", None)
if action_list is None:
raise AutoControlActionNullException(executor_list_error)
execute_record_dict = dict()
try:
if len(action_list) > 0 or type(action_list) is list:
Expand All @@ -84,6 +88,7 @@ def execute_action(self, action_list: list) -> dict:
execute_record_dict.update({execute_record: event_response})
except Exception as error:
print(repr(error), file=sys.stderr)
print(action, file=sys.stderr)
record_action_to_list("execute_action", None, repr(error))
return execute_record_dict

Expand Down

0 comments on commit d557b12

Please sign in to comment.