Skip to content

refactor & add feature #7

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

Merged
merged 4 commits into from
Nov 17, 2021
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
38 changes: 24 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,42 @@ jobs:

steps:
- checkout
# pip require package
- run:
command: pip install --user -r requirements.txt
name: pip requirements.txt
# screen test
- run:
command: python ./circle_ci_test/screen/screen_test.py
name: screen_test
- run:
command: python ./circle_ci_test/screen/screenshot_test.py
name: screenshot_test
# keyboard test
- run:
command: python ./circle_ci_test/keyboard/keyboard_type_test.py
name: keyboard_test
- run:
command: python ./circle_ci_test/mouse/mouse_test.py
name: mouse_test
- run:
command: python ./circle_ci_test/mouse/mouse_scroll_test.py
name: scroll_test
- run:
command: python ./circle_ci_test/keyboard/keyboard_write_test.py
name: keyboard_write_test
- run:
command: python ./circle_ci_test/screen/screenshot_test.py
name: screenshot_test
- run:
command: python ./circle_ci_test/exception/test_auto_control_exception.py
name: test_auto_control_exception
- run:
command: python ./circle_ci_test/keyboard/keyboard_is_press_test.py
name: keyboard_is_press_test
- run:
command: python ./circle_ci_test/keyboard/hotkey_test.py
name: hotkey_test
# mouse test
- run:
command: python ./circle_ci_test/mouse/mouse_test.py
name: mouse_test
- run:
command: python ./circle_ci_test/mouse/mouse_scroll_test.py
name: scroll_test
# exception test
- run:
command: python ./circle_ci_test/exception/test_auto_control_exception.py
name: test_auto_control_exception
# image detect
- run:
command: python ./circle_ci_test/image/locate_all_image_test.py
name: locate_all_image_test
Expand All @@ -50,21 +56,25 @@ jobs:
- run:
command: python ./circle_ci_test/image/locate_image_center_test.py
name: locate_image_center_test
# critical exit
- run:
command: python ./circle_ci_test/critical_exit/critical_exit_test.py
name: critical_exit_test
- run:
command: python ./circle_ci_test/critical_exit/real_critical_test.py
name: real_critical_test
# record
- run:
command: python ./circle_ci_test/record/record_test.py
name: record_test
# execute
- run:
command: python ./circle_ci_test/execute_action/execute_action_test.py
name: execute_action_test
# json
- run:
command: python ./circle_ci_test/execute_action/json_action_test.py
name: json_action_test
command: python ./circle_ci_test/json/json_test.py
name: json_test

workflows:
main:
Expand Down
30 changes: 16 additions & 14 deletions .idea/workspace.xml

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

7 changes: 4 additions & 3 deletions je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlJsonActionException
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlRecordException
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlActionNullException
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlActionException

# record
from je_auto_control.wrapper.auto_control_record import record
from je_auto_control.wrapper.auto_control_record import stop_record

# json
from je_auto_control.utils.action_executer.action_execute import execute_action
from je_auto_control.utils.action_file.json_loader import read_action_json
from je_auto_control.utils.action_file.json_loader import write_action_json
from je_auto_control.utils.action_executer.action_executor import execute_action
from je_auto_control.utils.action_file.json_file import read_action_json
from je_auto_control.utils.action_file.json_file import write_action_json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from je_auto_control import AutoControlActionException
from je_auto_control import AutoControlActionNullException
from je_auto_control import check_key_is_press
from je_auto_control import click_mouse
Expand All @@ -19,6 +20,8 @@
from je_auto_control import special_table
from je_auto_control import type_key
from je_auto_control import write
from je_auto_control.utils.je_auto_control_exception.exception_tag import action_is_null_error
from je_auto_control.utils.je_auto_control_exception.exception_tag import cant_execute_action_error

event_dict = {
# mouse
Expand Down Expand Up @@ -46,35 +49,43 @@
"locate_and_click": ("locate_and_click", locate_and_click),
# screen
"size": ("size", size),
"screenshot": ("screenshot", screenshot),
# python's basic function
"print": ("print", print)

"screenshot": ("screenshot", screenshot)
}


def execute_event(action):
event = event_dict.get(action[0])
if event[0] in ["click_mouse"]:
event[1](action[0], action[1], action[2])
elif event[0] in ["type_key", "press_key", "release_key", "check_key_is_press", "write"]:
event[1](action[1])
elif event[0] in ["position", "record", "stop_record", "size"]:
event[1]()
elif event[0] in ["set_position", "screenshot"]:
event[1](action[1], action[2])
elif event[0] in ["locate_all_image", "locate_image_center", "press_mouse", "release_mouse"]:
event[1](action[1], action[2], action[3])
elif event[0] in ["scroll", "locate_and_click"]:
event[1](action[1], action[2], action[3], action[4])


def execute_action(action_list: list):
"""
:param action_list the list include action
for loop the list and execute action
"""
execute_record_string = ""
if action_list is None:
raise AutoControlActionNullException
raise AutoControlActionNullException(action_is_null_error)
for action in action_list:
event = event_dict.get(action[0])
print("execute: ", str(action))
if event[0] in ["click_mouse"]:
event[1](action[0], action[1], action[2])
elif event[0] in ["type_key", "press_key", "release_key", "check_key_is_press", "write", "print"]:
event[1](action[1])
elif event[0] in ["position", "record", "stop_record", "size"]:
event[1]()
elif event[0] in ["set_position", "screenshot"]:
event[1](action[1], action[2])
elif event[0] in ["locate_all_image", "locate_image_center", "press_mouse", "release_mouse"]:
event[1](action[1], action[2], action[3])
elif event[0] in ["scroll", "locate_and_click"]:
event[1](action[1], action[2], action[3], action[4])
try:
execute_event(action)
except AutoControlActionException:
raise AutoControlActionException(cant_execute_action_error)
temp_string = "execute: " + str(action)
print(temp_string)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
return execute_record_string


if __name__ == "__main__":
Expand Down Expand Up @@ -105,5 +116,5 @@ def execute_action(action_list: list):
("press_mouse", "mouse_left", 500, 500),
("release_mouse", "mouse_left", 500, 500)
]
execute_action(test_list)

print("\n\n")
print(execute_action(test_list))
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"""
json action file tag
"""
cant_execute_action_error = "can't execute action"
cant_find_json_error = "can't find json file"
cant_save_json_error = "can't save json file"
action_is_null_error = "json action is null"
Expand Down
43 changes: 41 additions & 2 deletions je_auto_control/utils/je_auto_control_exception/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,73 @@
"""
general
"""


class AutoControlException(Exception):
pass


"""
Keyboard
"""


class AutoControlKeyboardException(AutoControlException):
pass


class AutoControlCantFindKeyException(AutoControlException):
pass


"""
Mouse
"""


class AutoControlMouseException(AutoControlException):
pass


"""
Screen
"""


class AutoControlScreenException(AutoControlException):
pass


class AutoControlCantFindKeyException(AutoControlException):
pass
"""
Image detect
"""


class ImageNotFoundException(AutoControlException):
pass


"""
Record
"""


class AutoControlRecordException(AutoControlException):
pass


"""
Execute action
"""


class AutoControlJsonActionException(AutoControlException):
pass


class AutoControlActionNullException(AutoControlException):
pass


class AutoControlActionException(AutoControlException):
pass
2 changes: 1 addition & 1 deletion je_auto_control/wrapper/auto_control_record.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from je_auto_control.utils.action_executer.action_execute import execute_action
from je_auto_control.utils.action_executer.action_executor import execute_action
from je_auto_control.utils.je_auto_control_exception.exception_tag import macos_record_error
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlException
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlJsonActionException
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="je_auto_control",
version="0.0.64",
version="0.0.66",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down