Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor executor & update dev ver #42

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .idea/workspace.xml

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ documentation available at [https://python-jeautocontrol.readthedocs.io/en/lates
## install

```
# make sure you have install cmake libssl-dev
# make sure you have install cmake libssl-dev (on linux)
pip install je_auto_control
```

Expand Down
2 changes: 1 addition & 1 deletion dev_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="je_auto_control_dev",
version="0.0.24",
version="0.0.25",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down
1 change: 1 addition & 0 deletions je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
# executor
from je_auto_control.utils.executor.action_executor import execute_action
from je_auto_control.utils.executor.action_executor import execute_files
from je_auto_control.utils.executor.action_executor import executor

# timeout
from je_auto_control.utils.timeout.multiprocess_timeout import multiprocess_timeout
Expand Down
152 changes: 82 additions & 70 deletions je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

from je_auto_control import AutoControlActionNullException
from je_auto_control import check_key_is_press
from je_auto_control import click_mouse
Expand All @@ -23,87 +24,98 @@
from je_auto_control.utils.exception.exception_tag import action_is_null_error
from je_auto_control.utils.exception.exception_tag import cant_execute_action_error
from je_auto_control.utils.exception.exceptions import AutoControlActionException
from je_auto_control.utils.html_report.html_report_generate import generate_html
from je_auto_control.utils.json.json_file import read_action_json

from je_auto_control.utils.test_record.record_test_class import record_action_to_list
from je_auto_control.utils.test_record.record_test_class import test_record_instance

from je_auto_control.utils.html_report.html_report_generate import generate_html

event_dict = {
# mouse
"mouse_left": click_mouse,
"mouse_right": click_mouse,
"mouse_middle": click_mouse,
"click_mouse": click_mouse,
"mouse_table": mouse_table,
"position": position,
"press_mouse": press_mouse,
"release_mouse": release_mouse,
"scroll": scroll,
"set_position": set_position,
"special_table": special_table,
# keyboard
"keys_table": keys_table,
"type_key": type_key,
"press_key": press_key,
"release_key": release_key,
"check_key_is_press": check_key_is_press,
"write": write,
"hotkey": hotkey,
# image
"locate_all_image": locate_all_image,
"locate_image_center": locate_image_center,
"locate_and_click": locate_and_click,
# screen
"size": size,
"screenshot": screenshot,
# test record
"set_record_enable": test_record_instance.set_record_enable,
# generate html
"generate_html": generate_html,
}
class Executor(object):

def __init__(self):
self.event_dict = {
# mouse
"mouse_left": click_mouse,
"mouse_right": click_mouse,
"mouse_middle": click_mouse,
"click_mouse": click_mouse,
"mouse_table": mouse_table,
"position": position,
"press_mouse": press_mouse,
"release_mouse": release_mouse,
"scroll": scroll,
"set_position": set_position,
"special_table": special_table,
# keyboard
"keys_table": keys_table,
"type_key": type_key,
"press_key": press_key,
"release_key": release_key,
"check_key_is_press": check_key_is_press,
"write": write,
"hotkey": hotkey,
# image
"locate_all_image": locate_all_image,
"locate_image_center": locate_image_center,
"locate_and_click": locate_and_click,
# screen
"size": size,
"screenshot": screenshot,
# test record
"set_record_enable": test_record_instance.set_record_enable,
# generate html
"generate_html": generate_html,
}

def execute_action(action_list: list) -> str:
"""
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
"""
execute_record_string = ""
try:
if len(action_list) > 0 or type(action_list) is list:
pass
else:
raise AutoControlActionNullException(action_is_null_error)
except Exception as error:
record_action_to_list("execute_action", action_list, repr(error))
print(repr(error), file=sys.stderr)
for action in action_list:
def execute_action(self, action_list: list) -> str:
"""
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
"""
execute_record_string = ""
try:
event = event_dict.get(action[0])
if len(action) == 2:
event(**action[1])
elif len(action) == 1:
event()
if len(action_list) > 0 or type(action_list) is list:
pass
else:
raise AutoControlActionException(cant_execute_action_error)
raise AutoControlActionNullException(action_is_null_error)
except Exception as error:
record_action_to_list("execute_action", action_list, repr(error))
print(repr(error), file=sys.stderr)
record_action_to_list("execute_action", None, repr(error))
temp_string = "execute: " + str(action)
print(temp_string)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
return execute_record_string
for action in action_list:
try:
event = self.event_dict.get(action[0])
if len(action) == 2:
event(**action[1])
elif len(action) == 1:
event()
else:
raise AutoControlActionException(cant_execute_action_error)
except Exception as error:
print(repr(error), file=sys.stderr)
record_action_to_list("execute_action", None, repr(error))
temp_string = "execute: " + str(action)
print(temp_string)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
return execute_record_string

def execute_files(self, execute_files_list: list) -> list:
"""
:param execute_files_list: list include execute files path
:return: every execute detail as list
"""
execute_detail_list = list()
for file in execute_files_list:
execute_detail_list.append(self.execute_action(read_action_json(file)))
return execute_detail_list


executor = Executor()


def execute_action(action_list: list) -> str:
return executor.execute_action(action_list)


def execute_files(execute_files_list: list) -> list:
"""
:param execute_files_list: list include execute files path
:return: every execute detail as list
"""
execute_detail_list = list()
for file in execute_files_list:
execute_detail_list.append(execute_action(read_action_json(file)))
return execute_detail_list
return executor.execute_files(execute_files_list)