-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
68 lines (60 loc) · 2.4 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# argparse
import argparse
import json
import sys
from automation_file.utils.exception.exception_tags import \
argparse_get_wrong_data
from automation_file.utils.exception.exceptions import \
ArgparseException
from automation_file.utils.executor.action_executor import execute_action
from automation_file.utils.executor.action_executor import execute_files
from automation_file.utils.file_process.get_dir_file_list import \
get_dir_files_as_list
from automation_file.utils.json.json_file import read_action_json
from automation_file.utils.project.create_project_structure import create_project_dir
if __name__ == "__main__":
try:
def preprocess_execute_action(file_path: str):
execute_action(read_action_json(file_path))
def preprocess_execute_files(file_path: str):
execute_files(get_dir_files_as_list(file_path))
def preprocess_read_str_execute_action(execute_str: str):
if sys.platform in ["win32", "cygwin", "msys"]:
json_data = json.loads(execute_str)
execute_str = json.loads(json_data)
else:
execute_str = json.loads(execute_str)
execute_action(execute_str)
argparse_event_dict = {
"execute_file": preprocess_execute_action,
"execute_dir": preprocess_execute_files,
"execute_str": preprocess_read_str_execute_action,
"create_project": create_project_dir
}
parser = argparse.ArgumentParser()
parser.add_argument(
"-e", "--execute_file",
type=str, help="choose action file to execute"
)
parser.add_argument(
"-d", "--execute_dir",
type=str, help="choose dir include action file to execute"
)
parser.add_argument(
"-c", "--create_project",
type=str, help="create project with template"
)
parser.add_argument(
"--execute_str",
type=str, help="execute json str"
)
args = parser.parse_args()
args = vars(args)
for key, value in args.items():
if value is not None:
argparse_event_dict.get(key)(value)
if all(value is None for value in args.values()):
raise ArgparseException(argparse_get_wrong_data)
except Exception as error:
print(repr(error), file=sys.stderr)
sys.exit(1)