Skip to content
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,7 @@ cython_debug/
.idea/

# Google Drive API token
tests/unit_test/remote/google_drive/credentials.json
token.json
credentials.json
**/token.json
**/credentials.json
2 changes: 1 addition & 1 deletion dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "automation_file_dev"
version = "0.0.16"
version = "0.0.17"
authors = [
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
]
Expand Down
64 changes: 64 additions & 0 deletions file_automation/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# argparse
import argparse
import json
import sys

from file_automation.utils.exception.exception_tags import \
argparse_get_wrong_data
from file_automation.utils.exception.exceptions import \
ArgparseException
from file_automation.utils.executor.action_executor import execute_action
from file_automation.utils.executor.action_executor import execute_files
from file_automation.utils.file_process.get_dir_file_list import \
get_dir_files_as_list
from file_automation.utils.json.json_file import read_action_json
from file_automation.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):
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)
2 changes: 2 additions & 0 deletions file_automation/utils/exception/exception_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
cant_find_json_error: str = "cant find json file"
cant_save_json_error: str = "cant save json file"
action_is_null_error: str = "json action is null"
# argparse
argparse_get_wrong_data: str = "argparse receive wrong data"
4 changes: 4 additions & 0 deletions file_automation/utils/exception/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ class AddCommandException(FileAutomationException):

class JsonActionException(FileAutomationException):
pass


class ArgparseException(FileAutomationException):
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "automation_file"
version = "0.0.14"
version = "0.0.15"
authors = [
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
]
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_test/executor/executor_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from file_automation import execute_action

test_list = [
["FA_drive_later_init", {"token_path": "token.json", "credentials_path": "credentials.json"}],
["FA_drive_search_all_file"],
["FA_drive_upload_to_drive", {"file_path": "test.txt"}],
["FA_drive_add_folder", {"folder_name": "test_folder"}],
["FA_drive_search_all_file"]
]

execute_action(test_list)
1 change: 1 addition & 0 deletions tests/unit_test/executor/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test123456789