Skip to content

Commit 7c09204

Browse files
authored
Merge pull request #22 from Integration-Automation/dev
Add CLI mode & Update dev and stable version
2 parents de28a1b + 8a6cbd6 commit 7c09204

8 files changed

Lines changed: 87 additions & 3 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,7 @@ cython_debug/
152152
.idea/
153153

154154
# Google Drive API token
155-
tests/unit_test/remote/google_drive/credentials.json
156155
token.json
156+
credentials.json
157+
**/token.json
158+
**/credentials.json

dev.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "automation_file_dev"
9-
version = "0.0.16"
9+
version = "0.0.17"
1010
authors = [
1111
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
1212
]

file_automation/__main__.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# argparse
2+
import argparse
3+
import json
4+
import sys
5+
6+
from file_automation.utils.exception.exception_tags import \
7+
argparse_get_wrong_data
8+
from file_automation.utils.exception.exceptions import \
9+
ArgparseException
10+
from file_automation.utils.executor.action_executor import execute_action
11+
from file_automation.utils.executor.action_executor import execute_files
12+
from file_automation.utils.file_process.get_dir_file_list import \
13+
get_dir_files_as_list
14+
from file_automation.utils.json.json_file import read_action_json
15+
from file_automation.utils.project.create_project_structure import create_project_dir
16+
17+
if __name__ == "__main__":
18+
try:
19+
def preprocess_execute_action(file_path: str):
20+
execute_action(read_action_json(file_path))
21+
22+
23+
def preprocess_execute_files(file_path: str):
24+
execute_files(get_dir_files_as_list(file_path))
25+
26+
27+
def preprocess_read_str_execute_action(execute_str: str):
28+
execute_str = json.loads(execute_str)
29+
execute_action(execute_str)
30+
31+
32+
argparse_event_dict = {
33+
"execute_file": preprocess_execute_action,
34+
"execute_dir": preprocess_execute_files,
35+
"execute_str": preprocess_read_str_execute_action,
36+
"create_project": create_project_dir
37+
}
38+
parser = argparse.ArgumentParser()
39+
parser.add_argument(
40+
"-e", "--execute_file",
41+
type=str, help="choose action file to execute"
42+
)
43+
parser.add_argument(
44+
"-d", "--execute_dir",
45+
type=str, help="choose dir include action file to execute"
46+
)
47+
parser.add_argument(
48+
"-c", "--create_project",
49+
type=str, help="create project with template"
50+
)
51+
parser.add_argument(
52+
"--execute_str",
53+
type=str, help="execute json str"
54+
)
55+
args = parser.parse_args()
56+
args = vars(args)
57+
for key, value in args.items():
58+
if value is not None:
59+
argparse_event_dict.get(key)(value)
60+
if all(value is None for value in args.values()):
61+
raise ArgparseException(argparse_get_wrong_data)
62+
except Exception as error:
63+
print(repr(error), file=sys.stderr)
64+
sys.exit(1)

file_automation/utils/exception/exception_tags.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
cant_find_json_error: str = "cant find json file"
1313
cant_save_json_error: str = "cant save json file"
1414
action_is_null_error: str = "json action is null"
15+
# argparse
16+
argparse_get_wrong_data: str = "argparse receive wrong data"

file_automation/utils/exception/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ class AddCommandException(FileAutomationException):
2828

2929
class JsonActionException(FileAutomationException):
3030
pass
31+
32+
33+
class ArgparseException(FileAutomationException):
34+
pass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "automation_file"
9-
version = "0.0.14"
9+
version = "0.0.15"
1010
authors = [
1111
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
1212
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from file_automation import execute_action
2+
3+
test_list = [
4+
["FA_drive_later_init", {"token_path": "token.json", "credentials_path": "credentials.json"}],
5+
["FA_drive_search_all_file"],
6+
["FA_drive_upload_to_drive", {"file_path": "test.txt"}],
7+
["FA_drive_add_folder", {"folder_name": "test_folder"}],
8+
["FA_drive_search_all_file"]
9+
]
10+
11+
execute_action(test_list)

tests/unit_test/executor/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test123456789

0 commit comments

Comments
 (0)