Skip to content

Commit 5aca927

Browse files
committed
Fix add module error & Add create project and template
Fix add module error & Add create project and template
1 parent be4d455 commit 5aca927

File tree

15 files changed

+153
-34
lines changed

15 files changed

+153
-34
lines changed

je_auto_control/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
from je_auto_control.utils.executor.action_executor import execute_action
3333
from je_auto_control.utils.executor.action_executor import execute_files
3434
from je_auto_control.utils.executor.action_executor import executor
35-
from je_auto_control.utils.file_process.create_project_structure import \
36-
create_template_dir
35+
from je_auto_control.utils.project.create_project_structure import \
36+
create_project_dir
3737
# file process
3838
from je_auto_control.utils.file_process.get_dir_file_list import \
3939
get_dir_files_as_list
@@ -119,7 +119,7 @@
119119
"generate_html", "generate_html_report",
120120
"generate_json", "generate_json_report",
121121
"generate_xml", "generate_xml_report",
122-
"get_dir_files_as_list", "create_template_dir",
122+
"get_dir_files_as_list", "create_project_dir",
123123
"start_autocontrol_socket_server",
124124
"callback_executor", "package_manager",
125125
"get_special_table"

je_auto_control/utils/callback/callback_function_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# executor
77
from je_auto_control.utils.executor.action_executor import execute_action
88
from je_auto_control.utils.executor.action_executor import execute_files
9-
from je_auto_control.utils.file_process.create_project_structure import create_template_dir
9+
from je_auto_control.utils.project.create_project_structure import create_project_dir
1010
# file process
1111
from je_auto_control.utils.file_process.get_dir_file_list import get_dir_files_as_list
1212
# html report
@@ -101,7 +101,7 @@ def __init__(self):
101101
# execute
102102
"execute_action": execute_action,
103103
"execute_files": execute_files,
104-
"create_template_dir": create_template_dir,
104+
"create_template_dir": create_project_dir,
105105
"get_dir_files_as_list": get_dir_files_as_list,
106106
"pil_screenshot": pil_screenshot,
107107
"read_action_json": read_action_json,

je_auto_control/utils/executor/action_executor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import time
33
import types
4+
import builtins
45
from inspect import getmembers, isbuiltin
56

67
from je_auto_control.utils.exception.exception_tags import action_is_null_error, add_command_exception_tag, \
@@ -80,9 +81,9 @@ def __init__(self):
8081
"add_package_to_executor": package_manager.add_package_to_executor,
8182
"add_package_to_callback_executor": package_manager.add_package_to_callback_executor
8283
}
83-
# get all time module builtin function and add to event dict
84-
for function in getmembers(time, isbuiltin):
85-
self.event_dict.update({str(function): function})
84+
# get all builtin function and add to event dict
85+
for function in getmembers(builtins, isbuiltin):
86+
self.event_dict.update({str(function[0]): function[1]})
8687

8788
def _execute_event(self, action: list):
8889
event = self.event_dict.get(action[0])

je_auto_control/utils/file_process/create_project_structure.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

je_auto_control/utils/generate_report/generate_html_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def generate_html_report(html_name: str = "default_name"):
154154
:param html_name: save html file name
155155
"""
156156
new_html_string = generate_html()
157+
_lock.acquire()
157158
try:
158-
_lock.acquire()
159159
with open(html_name + ".html", "w+") as file_to_write:
160160
file_to_write.write(
161161
new_html_string

je_auto_control/utils/generate_report/generate_json_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ def generate_json_report(json_file_name: str = "default_name"):
5555
"""
5656
lock = Lock()
5757
success_dict, failure_dict = generate_json()
58+
lock.acquire()
5859
try:
59-
lock.acquire()
6060
with open(json_file_name + "_success.json", "w+") as file_to_write:
6161
json.dump(dict(success_dict), file_to_write, indent=4)
6262
except Exception as error:
6363
print(repr(error), file=sys.stderr)
6464
finally:
6565
lock.release()
66+
lock.acquire()
6667
try:
67-
lock.acquire()
6868
with open(json_file_name + "_failure.json", "w+") as file_to_write:
6969
json.dump(dict(failure_dict), file_to_write, indent=4)
7070
except Exception as error:

je_auto_control/utils/generate_report/generate_xml_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ def generate_xml_report(xml_file_name: str = "default_name"):
2727
success_xml = success_xml.toprettyxml()
2828
failure_xml = failure_xml.toprettyxml()
2929
lock = Lock()
30+
lock.acquire()
3031
try:
31-
lock.acquire()
3232
with open(xml_file_name + "_failure.xml", "w+") as file_to_write:
3333
file_to_write.write(failure_xml)
3434
except Exception as error:
3535
print(repr(error), file=sys.stderr)
3636
finally:
3737
lock.release()
38+
lock.acquire()
3839
try:
39-
lock.acquire()
4040
with open(xml_file_name + "_success.xml", "w+") as file_to_write:
4141
file_to_write.write(success_xml)
4242
pass

je_auto_control/utils/json/json_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def read_action_json(json_file_path: str) -> list:
1414
use to read action file
1515
:param json_file_path json file's path to read
1616
"""
17+
_lock.acquire()
1718
try:
18-
_lock.acquire()
1919
file_path = Path(json_file_path)
2020
if file_path.exists() and file_path.is_file():
2121
with open(json_file_path) as read_file:
@@ -32,10 +32,10 @@ def write_action_json(json_save_path: str, action_json: list) -> None:
3232
:param json_save_path json save path
3333
:param action_json the json str include action to write
3434
"""
35+
_lock.acquire()
3536
try:
36-
_lock.acquire()
3737
with open(json_save_path, "w+") as file_to_write:
38-
file_to_write.write(json.dumps(action_json))
38+
file_to_write.write(json.dumps(action_json, indent=4))
3939
except AutoControlJsonActionException:
4040
raise AutoControlJsonActionException(cant_save_json_error)
4141
finally:

je_auto_control/utils/project/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from pathlib import Path
2+
from os import getcwd
3+
from threading import Lock
4+
5+
from je_auto_control.utils.json.json_file import write_action_json
6+
from je_auto_control.utils.project.template.template_executor import executor_template_1, \
7+
executor_template_2
8+
from je_auto_control.utils.project.template.template_keyword import template_keyword_1, \
9+
template_keyword_2
10+
11+
12+
def create_dir(dir_name: str) -> None:
13+
"""
14+
:param dir_name: create dir use dir name
15+
:return: None
16+
"""
17+
Path(dir_name).mkdir(
18+
parents=True,
19+
exist_ok=True
20+
)
21+
22+
23+
def create_template(parent_name: str) -> None:
24+
keyword_dir_path = Path(getcwd() + "/" + parent_name + "/keyword")
25+
executor_dir_path = Path(getcwd() + "/" + parent_name + "/executor")
26+
lock = Lock()
27+
if keyword_dir_path.exists() and keyword_dir_path.is_dir():
28+
write_action_json(getcwd() + "/" + parent_name + "/keyword/keyword1.json", template_keyword_1)
29+
write_action_json(getcwd() + "/" + parent_name + "/keyword/keyword2.json", template_keyword_2)
30+
if executor_dir_path.exists() and keyword_dir_path.is_dir():
31+
lock.acquire()
32+
try:
33+
with open(getcwd() + "/" + parent_name + "/executor/executor_one_file.py", "w+") as file:
34+
file.write(
35+
executor_template_1.replace(
36+
"{temp}",
37+
getcwd() + "/" + parent_name + "/keyword/keyword1.json"
38+
)
39+
)
40+
with open(getcwd() + "/" + parent_name + "/executor/executor_folder.py", "w+") as file:
41+
file.write(
42+
executor_template_2.replace(
43+
"{temp}",
44+
getcwd() + "/" + parent_name + "/keyword"
45+
)
46+
)
47+
finally:
48+
lock.release()
49+
50+
51+
def create_project_dir(parent_name: str) -> None:
52+
create_dir(getcwd() + "/" + parent_name + "/keyword")
53+
create_dir(getcwd() + "/" + parent_name + "/executor")
54+
create_template(parent_name)

0 commit comments

Comments
 (0)