Skip to content

Commit

Permalink
Add logger and update dev version
Browse files Browse the repository at this point in the history
Add logger and update dev version
  • Loading branch information
JE-Chen committed Jun 13, 2023
1 parent e6ef791 commit d212abd
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 20 deletions.
12 changes: 3 additions & 9 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = "je_auto_control_dev"
version = "0.0.81"
version = "0.0.82"
authors = [
{ name = "JE-Chen", email = "[email protected]" },
]
Expand Down
12 changes: 9 additions & 3 deletions je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from je_auto_control.utils.generate_report.generate_xml_report import generate_xml
from je_auto_control.utils.generate_report.generate_xml_report import generate_xml_report
from je_auto_control.utils.json.json_file import read_action_json
from je_auto_control.utils.logging.loggin_instance import auto_control_logger
from je_auto_control.utils.package_manager.package_manager_class import package_manager
from je_auto_control.utils.project.create_project_structure import create_project_dir
from je_auto_control.utils.shell_process.shell_exec import ShellManager
Expand Down Expand Up @@ -111,6 +112,7 @@ def execute_action(self, action_list: [list, dict]) -> dict:
:param action_list the list include action
for loop the list and execute action
"""
auto_control_logger.info(f"execute_action, action_list: {action_list}")
if isinstance(action_list, dict):
action_list: list = action_list.get("auto_control", None)
if action_list is None:
Expand All @@ -123,15 +125,18 @@ def execute_action(self, action_list: [list, dict]) -> dict:
raise AutoControlActionNullException(action_is_null_error)
except Exception as error:
record_action_to_list("execute_action", action_list, repr(error))
print(repr(error), file=sys.stderr, flush=True)
auto_control_logger.info(
f"execute_action, action_list: {action_list}, "
f"failed: {repr(error)}")
for action in action_list:
try:
event_response = self._execute_event(action)
execute_record = "execute: " + str(action)
execute_record_dict.update({execute_record: event_response})
except Exception as error:
print(repr(error), file=sys.stderr, flush=True)
print(action, file=sys.stderr, flush=True)
auto_control_logger.info(
f"execute_action, action_list: {action_list}, "
f"action: {action}, failed: {repr(error)}")
record_action_to_list("execute_action", None, repr(error))
execute_record = "execute: " + str(action)
execute_record_dict.update({execute_record: repr(error)})
Expand All @@ -145,6 +150,7 @@ def execute_files(self, execute_files_list: list) -> list:
:param execute_files_list: list include execute files path
:return: every execute detail as list
"""
auto_control_logger.info(f"execute_files, execute_files_list: {execute_files_list}")
execute_detail_list: list = list()
for file in execute_files_list:
execute_detail_list.append(self.execute_action(read_action_json(file)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from je_auto_control.utils.exception.exception_tags import html_generate_no_data_tag
from je_auto_control.utils.exception.exceptions import AutoControlHTMLException
from je_auto_control.utils.logging.loggin_instance import auto_control_logger
from je_auto_control.utils.test_record.record_test_class import test_record_instance

_lock = Lock()
Expand Down Expand Up @@ -130,6 +131,7 @@ def make_html_table(event_str: str, record_data: dict, table_head: str) -> str:


def generate_html() -> str:
auto_control_logger.info("generate_html")
"""
this function will create html string
:return: html_string
Expand All @@ -149,6 +151,7 @@ def generate_html() -> str:


def generate_html_report(html_name: str = "default_name"):
auto_control_logger.info(f"generate_html_report, html_name: {html_name}")
"""
Output html report file
:param html_name: save html file name
Expand All @@ -161,6 +164,7 @@ def generate_html_report(html_name: str = "default_name"):
new_html_string
)
except Exception as error:
print(repr(error), file=sys.stderr)
auto_control_logger.error(
f"generate_html_report, html_name: {html_name}, failed: {repr(error)}")
finally:
_lock.release()
11 changes: 9 additions & 2 deletions je_auto_control/utils/generate_report/generate_json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

from je_auto_control.utils.exception.exception_tags import cant_generate_json_report
from je_auto_control.utils.exception.exceptions import AutoControlGenerateJsonReportException
from je_auto_control.utils.logging.loggin_instance import auto_control_logger
from je_auto_control.utils.test_record.record_test_class import test_record_instance


def generate_json():
auto_control_logger.info("generate_json")
"""
:return: two dict {success_dict}, {failure_dict}
"""
Expand Down Expand Up @@ -49,6 +51,7 @@ def generate_json():


def generate_json_report(json_file_name: str = "default_name"):
auto_control_logger.info(f"generate_json_report, json_file_name: {json_file_name}")
"""
Output json report file
:param json_file_name: save json file's name
Expand All @@ -60,14 +63,18 @@ def generate_json_report(json_file_name: str = "default_name"):
with open(json_file_name + "_success.json", "w+") as file_to_write:
json.dump(dict(success_dict), file_to_write, indent=4)
except Exception as error:
print(repr(error), file=sys.stderr)
auto_control_logger.error(
f"generate_json_report, json_file_name: {json_file_name}, "
f"failed: {repr(error)}")
finally:
lock.release()
lock.acquire()
try:
with open(json_file_name + "_failure.json", "w+") as file_to_write:
json.dump(dict(failure_dict), file_to_write, indent=4)
except Exception as error:
print(repr(error), file=sys.stderr)
auto_control_logger.error(
f"generate_json_report, json_file_name: {json_file_name}, "
f"failed: {repr(error)}")
finally:
lock.release()
12 changes: 10 additions & 2 deletions je_auto_control/utils/generate_report/generate_xml_report.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import sys
from threading import Lock
from xml.dom.minidom import parseString

from je_auto_control.utils.generate_report.generate_json_report import generate_json
from je_auto_control.utils.logging.loggin_instance import auto_control_logger
from je_auto_control.utils.xml.change_xml_structure.change_xml_structure import dict_to_elements_tree


def generate_xml():
auto_control_logger.info("generate_xml")
"""
:return: two dict {success_dict}, {failure_dict}
"""
Expand All @@ -18,6 +21,7 @@ def generate_xml():


def generate_xml_report(xml_file_name: str = "default_name"):
auto_control_logger.info(f"generate_xml_report, xml_file_name: {xml_file_name}")
"""
:param xml_file_name: save xml file name
"""
Expand All @@ -32,7 +36,9 @@ def generate_xml_report(xml_file_name: str = "default_name"):
with open(xml_file_name + "_failure.xml", "w+") as file_to_write:
file_to_write.write(failure_xml)
except Exception as error:
print(repr(error), file=sys.stderr)
auto_control_logger.error(
f"generate_xml_report, xml_file_name: {xml_file_name}, "
f"failed: {repr(error)}")
finally:
lock.release()
lock.acquire()
Expand All @@ -41,7 +47,9 @@ def generate_xml_report(xml_file_name: str = "default_name"):
file_to_write.write(success_xml)
pass
except Exception as error:
print(repr(error), file=sys.stderr)
auto_control_logger.error(
f"generate_xml_report, xml_file_name: {xml_file_name}, "
f"failed: {repr(error)}")
finally:
lock.release()

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from inspect import getmembers, isfunction, isbuiltin, isclass
from sys import stderr

from je_auto_control.utils.logging.loggin_instance import auto_control_logger


class PackageManager(object):

Expand All @@ -29,6 +31,7 @@ def check_package(self, package: str):
return self.installed_package_dict.get(package, None)

def add_package_to_executor(self, package):
auto_control_logger.info(f"add_package_to_executor, package: {package}")
"""
:param package: package's function will add to executor
"""
Expand All @@ -38,6 +41,7 @@ def add_package_to_executor(self, package):
)

def add_package_to_callback_executor(self, package):
auto_control_logger.info(f"add_package_to_callback_executor, package: {package}")
"""
:param package: package's function will add to callback_executor
"""
Expand Down
2 changes: 2 additions & 0 deletions je_auto_control/utils/project/create_project_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from threading import Lock

from je_auto_control.utils.json.json_file import write_action_json
from je_auto_control.utils.logging.loggin_instance import auto_control_logger
from je_auto_control.utils.project.template.template_executor import executor_template_1, \
executor_template_2, bad_executor_template_1
from je_auto_control.utils.project.template.template_keyword import template_keyword_1, \
Expand Down Expand Up @@ -59,6 +60,7 @@ def create_template(parent_name: str, project_path: str = None) -> None:


def create_project_dir(project_path: str = None, parent_name: str = "AutoControl") -> None:
auto_control_logger.info(f"create_project_dir, project_path: {project_path}, parent_name: {parent_name}")
if project_path is None:
project_path = getcwd()
create_dir(project_path + "/" + parent_name + "/keyword")
Expand Down
6 changes: 5 additions & 1 deletion je_auto_control/utils/shell_process/shell_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sys
from threading import Thread

from je_auto_control.utils.logging.loggin_instance import auto_control_logger


class ShellManager(object):

Expand All @@ -30,6 +32,7 @@ def exec_shell(self, shell_command: [str, list]) -> None:
:param shell_command: shell command will run
:return: if error return result and True else return result and False
"""
auto_control_logger.info(f"exec_shell, shell_command: {shell_command}")
try:
self.exit_program()
if sys.platform in ["win32", "cygwin", "msys"]:
Expand All @@ -56,7 +59,8 @@ def exec_shell(self, shell_command: [str, list]) -> None:
)
self.read_program_error_output_from_thread.start()
except Exception as error:
print(repr(error), file=sys.stderr)
auto_control_logger.error(
f"exec_shell, shell_command: {shell_command}, failed: {repr(error)}")

# tkinter_ui update method
def pull_text(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions je_auto_control/utils/start_exe/start_another_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

from je_auto_control.utils.exception.exception_tags import can_not_find_file
from je_auto_control.utils.exception.exceptions import AutoControlException
from je_auto_control.utils.logging.loggin_instance import auto_control_logger

from je_auto_control.utils.shell_process.shell_exec import ShellManager


def start_exe(exe_path: str):
auto_control_logger.info(f"start_exe, exe_path: {exe_path}")
exe_path = Path(exe_path)
if exe_path.exists() and exe_path.is_file():
process_manager = ShellManager()
process_manager.exec_shell(str(exe_path))
else:
auto_control_logger.error(
f"start_exe, exe_path: {exe_path}, failed: {AutoControlException(can_not_find_file)}")
raise AutoControlException(can_not_find_file)
3 changes: 3 additions & 0 deletions je_auto_control/utils/test_record/record_test_class.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime

from je_auto_control.utils.logging.loggin_instance import auto_control_logger


class TestRecord(object):

Expand All @@ -11,6 +13,7 @@ def clean_record(self) -> None:
self.test_record_list = list()

def set_record_enable(self, set_enable: bool = True):
auto_control_logger.info(f"set_record_enable, set_enable: {set_enable}")
self.init_record = set_enable


Expand Down
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 = "je_auto_control"
version = "0.0.142"
version = "0.0.143"
authors = [
{ name = "JE-Chen", email = "[email protected]" },
]
Expand Down

0 comments on commit d212abd

Please sign in to comment.