Skip to content

Commit 77caaee

Browse files
authored
Merge pull request #42 from JE-Chen/dev
refactor executor & update dev ver
2 parents 0f8de0c + 4b151be commit 77caaee

File tree

5 files changed

+94
-81
lines changed

5 files changed

+94
-81
lines changed

.idea/workspace.xml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ documentation available at [https://python-jeautocontrol.readthedocs.io/en/lates
2929
## install
3030

3131
```
32-
# make sure you have install cmake libssl-dev
32+
# make sure you have install cmake libssl-dev (on linux)
3333
pip install je_auto_control
3434
```
3535

dev_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="je_auto_control_dev",
8-
version="0.0.24",
8+
version="0.0.25",
99
author="JE-Chen",
1010
author_email="[email protected]",
1111
description="auto testing",

je_auto_control/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
# executor
5757
from je_auto_control.utils.executor.action_executor import execute_action
5858
from je_auto_control.utils.executor.action_executor import execute_files
59+
from je_auto_control.utils.executor.action_executor import executor
5960

6061
# timeout
6162
from je_auto_control.utils.timeout.multiprocess_timeout import multiprocess_timeout
Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
23
from je_auto_control import AutoControlActionNullException
34
from je_auto_control import check_key_is_press
45
from je_auto_control import click_mouse
@@ -23,87 +24,98 @@
2324
from je_auto_control.utils.exception.exception_tag import action_is_null_error
2425
from je_auto_control.utils.exception.exception_tag import cant_execute_action_error
2526
from je_auto_control.utils.exception.exceptions import AutoControlActionException
27+
from je_auto_control.utils.html_report.html_report_generate import generate_html
2628
from je_auto_control.utils.json.json_file import read_action_json
27-
2829
from je_auto_control.utils.test_record.record_test_class import record_action_to_list
2930
from je_auto_control.utils.test_record.record_test_class import test_record_instance
3031

31-
from je_auto_control.utils.html_report.html_report_generate import generate_html
3232

33-
event_dict = {
34-
# mouse
35-
"mouse_left": click_mouse,
36-
"mouse_right": click_mouse,
37-
"mouse_middle": click_mouse,
38-
"click_mouse": click_mouse,
39-
"mouse_table": mouse_table,
40-
"position": position,
41-
"press_mouse": press_mouse,
42-
"release_mouse": release_mouse,
43-
"scroll": scroll,
44-
"set_position": set_position,
45-
"special_table": special_table,
46-
# keyboard
47-
"keys_table": keys_table,
48-
"type_key": type_key,
49-
"press_key": press_key,
50-
"release_key": release_key,
51-
"check_key_is_press": check_key_is_press,
52-
"write": write,
53-
"hotkey": hotkey,
54-
# image
55-
"locate_all_image": locate_all_image,
56-
"locate_image_center": locate_image_center,
57-
"locate_and_click": locate_and_click,
58-
# screen
59-
"size": size,
60-
"screenshot": screenshot,
61-
# test record
62-
"set_record_enable": test_record_instance.set_record_enable,
63-
# generate html
64-
"generate_html": generate_html,
65-
}
33+
class Executor(object):
6634

35+
def __init__(self):
36+
self.event_dict = {
37+
# mouse
38+
"mouse_left": click_mouse,
39+
"mouse_right": click_mouse,
40+
"mouse_middle": click_mouse,
41+
"click_mouse": click_mouse,
42+
"mouse_table": mouse_table,
43+
"position": position,
44+
"press_mouse": press_mouse,
45+
"release_mouse": release_mouse,
46+
"scroll": scroll,
47+
"set_position": set_position,
48+
"special_table": special_table,
49+
# keyboard
50+
"keys_table": keys_table,
51+
"type_key": type_key,
52+
"press_key": press_key,
53+
"release_key": release_key,
54+
"check_key_is_press": check_key_is_press,
55+
"write": write,
56+
"hotkey": hotkey,
57+
# image
58+
"locate_all_image": locate_all_image,
59+
"locate_image_center": locate_image_center,
60+
"locate_and_click": locate_and_click,
61+
# screen
62+
"size": size,
63+
"screenshot": screenshot,
64+
# test record
65+
"set_record_enable": test_record_instance.set_record_enable,
66+
# generate html
67+
"generate_html": generate_html,
68+
}
6769

68-
def execute_action(action_list: list) -> str:
69-
"""
70-
use to execute all action on action list(action file or program list)
71-
:param action_list the list include action
72-
for loop the list and execute action
73-
"""
74-
execute_record_string = ""
75-
try:
76-
if len(action_list) > 0 or type(action_list) is list:
77-
pass
78-
else:
79-
raise AutoControlActionNullException(action_is_null_error)
80-
except Exception as error:
81-
record_action_to_list("execute_action", action_list, repr(error))
82-
print(repr(error), file=sys.stderr)
83-
for action in action_list:
70+
def execute_action(self, action_list: list) -> str:
71+
"""
72+
use to execute all action on action list(action file or program list)
73+
:param action_list the list include action
74+
for loop the list and execute action
75+
"""
76+
execute_record_string = ""
8477
try:
85-
event = event_dict.get(action[0])
86-
if len(action) == 2:
87-
event(**action[1])
88-
elif len(action) == 1:
89-
event()
78+
if len(action_list) > 0 or type(action_list) is list:
79+
pass
9080
else:
91-
raise AutoControlActionException(cant_execute_action_error)
81+
raise AutoControlActionNullException(action_is_null_error)
9282
except Exception as error:
83+
record_action_to_list("execute_action", action_list, repr(error))
9384
print(repr(error), file=sys.stderr)
94-
record_action_to_list("execute_action", None, repr(error))
95-
temp_string = "execute: " + str(action)
96-
print(temp_string)
97-
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
98-
return execute_record_string
85+
for action in action_list:
86+
try:
87+
event = self.event_dict.get(action[0])
88+
if len(action) == 2:
89+
event(**action[1])
90+
elif len(action) == 1:
91+
event()
92+
else:
93+
raise AutoControlActionException(cant_execute_action_error)
94+
except Exception as error:
95+
print(repr(error), file=sys.stderr)
96+
record_action_to_list("execute_action", None, repr(error))
97+
temp_string = "execute: " + str(action)
98+
print(temp_string)
99+
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
100+
return execute_record_string
101+
102+
def execute_files(self, execute_files_list: list) -> list:
103+
"""
104+
:param execute_files_list: list include execute files path
105+
:return: every execute detail as list
106+
"""
107+
execute_detail_list = list()
108+
for file in execute_files_list:
109+
execute_detail_list.append(self.execute_action(read_action_json(file)))
110+
return execute_detail_list
111+
112+
113+
executor = Executor()
114+
115+
116+
def execute_action(action_list: list) -> str:
117+
return executor.execute_action(action_list)
99118

100119

101120
def execute_files(execute_files_list: list) -> list:
102-
"""
103-
:param execute_files_list: list include execute files path
104-
:return: every execute detail as list
105-
"""
106-
execute_detail_list = list()
107-
for file in execute_files_list:
108-
execute_detail_list.append(execute_action(read_action_json(file)))
109-
return execute_detail_list
121+
return executor.execute_files(execute_files_list)

0 commit comments

Comments
 (0)