Skip to content

Commit 756bb03

Browse files
authored
Merge pull request #15 from Integration-Automation/dev
Dev
2 parents 2e275dd + ed869a7 commit 756bb03

8 files changed

Lines changed: 68 additions & 20 deletions

File tree

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.7"
9+
version = "0.0.8"
1010
authors = [
1111
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
1212
]

file_automation/local/zip/zip_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ def set_zip_password(zip_file_path: str, password: bytes):
9898
file_automation_logger.info(
9999
f"Set zip file password, "
100100
f"zip file: {zip_file_path}, "
101-
f"zup password: {password}"
101+
f"zip password: {password}"
102102
)

file_automation/utils/callback/callback_function_executor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import typing
2-
from sys import stderr
32

43
from file_automation.local.dir.dir_process import copy_dir, create_dir, remove_dir_tree
54
from file_automation.local.file.file_process import copy_file, remove_file, rename_file, copy_specify_extension_file, \
@@ -18,6 +17,7 @@
1817
upload_dir_to_folder, upload_to_folder, upload_dir_to_drive, upload_to_drive
1918
from file_automation.utils.exception.exception_tags import get_bad_trigger_function, get_bad_trigger_method
2019
from file_automation.utils.exception.exceptions import CallbackExecutorException
20+
from file_automation.utils.logging.loggin_instance import file_automation_logger
2121

2222

2323
class CallbackFunctionExecutor(object):
@@ -76,19 +76,26 @@ def callback_function(
7676
try:
7777
if trigger_function_name not in self.event_dict.keys():
7878
raise CallbackExecutorException(get_bad_trigger_function)
79+
file_automation_logger.info(f"Callback trigger {trigger_function_name} with param {kwargs}")
7980
execute_return_value = self.event_dict.get(trigger_function_name)(**kwargs)
8081
if callback_function_param is not None:
8182
if callback_param_method not in ["kwargs", "args"]:
8283
raise CallbackExecutorException(get_bad_trigger_method)
8384
if callback_param_method == "kwargs":
8485
callback_function(**callback_function_param)
86+
file_automation_logger.info(
87+
f"Callback function {callback_function} with param {callback_function_param}")
8588
else:
8689
callback_function(*callback_function_param)
90+
file_automation_logger.info(
91+
f"Callback function {callback_function} with param {callback_function_param}")
8792
else:
8893
callback_function()
94+
file_automation_logger.info(f"Callback function {callback_function}")
8995
return execute_return_value
9096
except Exception as error:
91-
print(repr(error), file=stderr)
97+
file_automation_logger.error(
98+
f"Callback function failed. {repr(error)}")
9299

93100

94101
callback_executor = CallbackFunctionExecutor()

file_automation/utils/executor/action_executor.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
action_is_null_error, cant_execute_action_error
2323
from file_automation.utils.exception.exceptions import ExecuteActionException, AddCommandException
2424
from file_automation.utils.json.json_file import read_action_json
25+
from file_automation.utils.logging.loggin_instance import file_automation_logger
2526

2627

2728
class Executor(object):
@@ -93,20 +94,23 @@ def execute_action(self, action_list: [list, dict]) -> dict:
9394
else:
9495
raise ExecuteActionException(action_is_null_error)
9596
except Exception as error:
96-
print(repr(error), file=sys.stderr, flush=True)
97+
file_automation_logger.error(
98+
f"Execute {action_list} failed. {repr(error)}"
99+
)
97100
for action in action_list:
98101
try:
99102
event_response = self._execute_event(action)
100103
execute_record = "execute: " + str(action)
104+
file_automation_logger.info(
105+
f"Execute {action}"
106+
)
101107
execute_record_dict.update({execute_record: event_response})
102108
except Exception as error:
103-
print(repr(error), file=sys.stderr, flush=True)
104-
print(action, file=sys.stderr, flush=True)
109+
file_automation_logger.error(
110+
f"Execute {action} failed. {repr(error)}"
111+
)
105112
execute_record = "execute: " + str(action)
106113
execute_record_dict.update({execute_record: repr(error)})
107-
for key, value in execute_record_dict.items():
108-
print(key, flush=True)
109-
print(value, flush=True)
110114
return execute_record_dict
111115

112116
def execute_files(self, execute_files_list: list) -> list:
@@ -127,6 +131,9 @@ def add_command_to_executor(command_dict: dict):
127131
"""
128132
:param command_dict: dict include command we want to add to event_dict
129133
"""
134+
file_automation_logger.info(
135+
f"Add command to executor {command_dict}"
136+
)
130137
for command_name, command in command_dict.items():
131138
if isinstance(command, (types.MethodType, types.FunctionType)):
132139
executor.event_dict.update({command_name: command})

file_automation/utils/json/json_file.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from pathlib import Path
33
from threading import Lock
44

5-
from file_automation.utils.exception.exception_tags import cant_find_json_error
5+
from file_automation.utils.exception.exception_tags import cant_find_json_error, cant_save_json_error
66
from file_automation.utils.exception.exceptions import JsonActionException
7+
from file_automation.utils.logging.loggin_instance import file_automation_logger
78

89
_lock = Lock()
910

@@ -17,6 +18,9 @@ def read_action_json(json_file_path: str) -> list:
1718
try:
1819
file_path = Path(json_file_path)
1920
if file_path.exists() and file_path.is_file():
21+
file_automation_logger.info(
22+
f"Read json file {json_file_path}"
23+
)
2024
with open(json_file_path) as read_file:
2125
return json.loads(read_file.read())
2226
except JsonActionException:
@@ -33,9 +37,12 @@ def write_action_json(json_save_path: str, action_json: list) -> None:
3337
"""
3438
_lock.acquire()
3539
try:
40+
file_automation_logger.info(
41+
f"Write {action_json} as file {json_save_path}"
42+
)
3643
with open(json_save_path, "w+") as file_to_write:
3744
file_to_write.write(json.dumps(action_json, indent=4))
38-
except AutoControlJsonActionException:
39-
raise AutoControlJsonActionException(cant_save_json_error)
45+
except JsonActionException:
46+
raise JsonActionException(cant_save_json_error)
4047
finally:
4148
_lock.release()
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import logging
2+
import sys
23

3-
logging.getLogger().setLevel(logging.INFO)
44
file_automation_logger = logging.getLogger("File Automation")
5-
handler = logging.StreamHandler()
6-
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
7-
handler.setFormatter(formatter)
8-
file_automation_logger.addHandler(handler)
9-
file_automation_logger.setLevel(logging.DEBUG)
5+
file_automation_logger.setLevel(logging.INFO)
6+
formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s')
7+
# Stream handler
8+
stream_handler = logging.StreamHandler(stream=sys.stderr)
9+
stream_handler.setFormatter(formatter)
10+
stream_handler.setLevel(logging.WARNING)
11+
file_automation_logger.addHandler(stream_handler)
12+
# File handler
13+
file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w+")
14+
file_handler.setFormatter(formatter)
15+
file_automation_logger.addHandler(file_handler)
16+

file_automation/utils/scheduler/extend_apscheduler.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from apscheduler.schedulers.blocking import BlockingScheduler
55
from apscheduler.util import undefined
66

7+
from file_automation.utils.logging.loggin_instance import file_automation_logger
8+
79

810
class SchedulerManager(object):
911

@@ -38,9 +40,15 @@ def get_nonblocking_scheduler(self):
3840
return self._background_schedulers
3941

4042
def start_block_scheduler(self, *args, **kwargs):
43+
file_automation_logger.info(
44+
f"Start blocking scheduler with {args}, {kwargs}"
45+
)
4146
self._blocking_schedulers.start(*args, **kwargs)
4247

4348
def start_nonblocking_scheduler(self, *args, **kwargs):
49+
file_automation_logger.info(
50+
f"Start background scheduler with {args}, {kwargs}"
51+
)
4452
self._background_schedulers.start(*args, **kwargs)
4553

4654
def start_all_scheduler(self, *args, **kwargs):
@@ -116,13 +124,25 @@ def add_cron_nonblocking(
116124
self.add_nonblocking_job(func=function, id=id, trigger="cron", **trigger_args)
117125

118126
def remove_blocking_job(self, id: str, jobstore: str = 'default'):
127+
file_automation_logger.info(
128+
f"Remove blocking job {id}, store on {jobstore}"
129+
)
119130
self._blocking_schedulers.remove_job(job_id=id, jobstore=jobstore)
120131

121132
def remove_nonblocking_job(self, id: str, jobstore: str = 'default'):
133+
file_automation_logger.info(
134+
f"Remove nonblocking job {id}, store on {jobstore}"
135+
)
122136
self._background_schedulers.remove_job(job_id=id, jobstore=jobstore)
123137

124138
def shutdown_blocking_scheduler(self, wait: bool = False):
139+
file_automation_logger.info(
140+
f"Shutdown blocking scheduler wait = {wait}"
141+
)
125142
self._blocking_schedulers.shutdown(wait=wait)
126143

127144
def shutdown_nonblocking_scheduler(self, wait: bool = False):
145+
file_automation_logger.info(
146+
f"Shutdown nonblocking scheduler wait = {wait}"
147+
)
128148
self._background_schedulers.shutdown(wait=wait)

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.6"
9+
version = "0.0.7"
1010
authors = [
1111
{ name = "JE-Chen", email = "zenmailman@gmail.com" },
1212
]

0 commit comments

Comments
 (0)