|
1 | 1 | import sys |
| 2 | + |
2 | 3 | from je_auto_control import AutoControlActionNullException |
3 | 4 | from je_auto_control import check_key_is_press |
4 | 5 | from je_auto_control import click_mouse |
|
23 | 24 | from je_auto_control.utils.exception.exception_tag import action_is_null_error |
24 | 25 | from je_auto_control.utils.exception.exception_tag import cant_execute_action_error |
25 | 26 | from je_auto_control.utils.exception.exceptions import AutoControlActionException |
| 27 | +from je_auto_control.utils.html_report.html_report_generate import generate_html |
26 | 28 | from je_auto_control.utils.json.json_file import read_action_json |
27 | | - |
28 | 29 | from je_auto_control.utils.test_record.record_test_class import record_action_to_list |
29 | 30 | from je_auto_control.utils.test_record.record_test_class import test_record_instance |
30 | 31 |
|
31 | | -from je_auto_control.utils.html_report.html_report_generate import generate_html |
32 | 32 |
|
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): |
66 | 34 |
|
| 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 | + } |
67 | 69 |
|
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 = "" |
84 | 77 | 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 |
90 | 80 | else: |
91 | | - raise AutoControlActionException(cant_execute_action_error) |
| 81 | + raise AutoControlActionNullException(action_is_null_error) |
92 | 82 | except Exception as error: |
| 83 | + record_action_to_list("execute_action", action_list, repr(error)) |
93 | 84 | 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) |
99 | 118 |
|
100 | 119 |
|
101 | 120 | 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