diff --git a/.idea/misc.xml b/.idea/misc.xml index 35233d5..2cefeb6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/automation_file/gui/__init__.py b/automation_file/gui/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/automation_file/gui/main_widget.py b/automation_file/gui/main_widget.py new file mode 100644 index 0000000..999b0e7 --- /dev/null +++ b/automation_file/gui/main_widget.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from je_auto_control.gui.main_window import AutoControlGUI + +from PySide6.QtWidgets import QWidget, QGridLayout + + +class AutoControlWidget(QWidget): + + def __init__(self, main_ui: AutoControlGUI): + super().__init__() + # Variable + self.main_ui = main_ui + # UI component + # Grid layout + self.grid_layout = QGridLayout() + self.setLayout(self.grid_layout) diff --git a/automation_file/gui/main_window.py b/automation_file/gui/main_window.py new file mode 100644 index 0000000..791490f --- /dev/null +++ b/automation_file/gui/main_window.py @@ -0,0 +1,44 @@ +import os +import sys +from pathlib import Path + +from PySide6.QtCore import QCoreApplication, QTimer +from PySide6.QtGui import QIcon +from PySide6.QtWidgets import QMainWindow, QApplication +from qt_material import apply_stylesheet + +from je_auto_control.gui.main_widget import AutoControlWidget + + +class AutoControlGUI(QMainWindow): + + def __init__(self, debug_mode: bool = False): + super().__init__() + self.debug_mode = debug_mode + self.central_widget = AutoControlWidget(self) + self.setCentralWidget(self.central_widget) + self.setWindowTitle("AutoControlGUI") + # Set Icon + self.icon_path = Path(os.getcwd() + "/je_driver_icon.ico") + self.icon = QIcon(str(self.icon_path)) + if self.icon.isNull() is False: + self.setWindowIcon(self.icon) + if self.debug_mode: + close_timer = QTimer(self) + close_timer.setInterval(10000) + close_timer.timeout.connect(self.debug_close) + close_timer.start() + + @classmethod + def debug_close(cls): + sys.exit(0) + + +def start_autocontrol_gui(debug_mode: bool = False) -> None: + autocontrol_gui = QCoreApplication.instance() + if autocontrol_gui is None: + autocontrol_gui = QApplication(sys.argv) + window = AutoControlGUI(debug_mode) + apply_stylesheet(autocontrol_gui, theme='dark_amber.xml') + window.showMaximized() + sys.exit(autocontrol_gui.exec()) diff --git a/automation_file/local/file/file_process.py b/automation_file/local/file/file_process.py index 2acfcef..c6a1081 100644 --- a/automation_file/local/file/file_process.py +++ b/automation_file/local/file/file_process.py @@ -6,16 +6,20 @@ from automation_file.utils.logging.loggin_instance import file_automation_logger -def copy_file(file_path: str, target_path: str) -> bool: +def copy_file(file_path: str, target_path: str, copy_metadata: bool = True) -> bool: """ :param file_path: which file do we want to copy (str path) :param target_path: put copy file on target path + :param copy_metadata: copy file metadata or not :return: True if success else False """ file_path = Path(file_path) if file_path.is_file() and file_path.exists(): try: - shutil.copy2(file_path, target_path) + if copy_metadata: + shutil.copy2(file_path, target_path) + else: + shutil.copy(file_path, target_path) file_automation_logger.info(f"Copy file origin path: {file_path}, target path : {target_path}") return True except shutil.Error as error: @@ -25,17 +29,19 @@ def copy_file(file_path: str, target_path: str) -> bool: return False -def copy_specify_extension_file(file_dir_path: str, target_extension: str, target_path: str) -> bool: +def copy_specify_extension_file( + file_dir_path: str, target_extension: str, target_path: str, copy_metadata: bool = True) -> bool: """ :param file_dir_path: which dir do we want to search :param target_extension: what extension we will search :param target_path: copy file to target path + :param copy_metadata: copy file metadata or not :return: True if success else False """ file_dir_path = Path(file_dir_path) if file_dir_path.exists() and file_dir_path.is_dir(): for file in file_dir_path.glob(f"**/*.{target_extension}"): - copy_file(str(file), target_path) + copy_file(str(file), target_path, copy_metadata=copy_metadata) file_automation_logger.info( f"Copy specify extension file on dir" f"origin dir path: {file_dir_path}, target extension: {target_extension}, " diff --git a/automation_file/utils/logging/loggin_instance.py b/automation_file/utils/logging/loggin_instance.py index 63b5da1..6887b04 100644 --- a/automation_file/utils/logging/loggin_instance.py +++ b/automation_file/utils/logging/loggin_instance.py @@ -1,16 +1,27 @@ import logging -import sys +logging.root.setLevel(logging.DEBUG) file_automation_logger = logging.getLogger("File Automation") -file_automation_logger.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s') -# Stream handler -stream_handler = logging.StreamHandler(stream=sys.stderr) -stream_handler.setFormatter(formatter) -stream_handler.setLevel(logging.WARNING) -file_automation_logger.addHandler(stream_handler) # File handler -file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w+") +file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w") file_handler.setFormatter(formatter) file_automation_logger.addHandler(file_handler) +class FileAutomationLoggingHandler(logging.Handler): + + # redirect logging stderr output to queue + + def __init__(self): + super().__init__() + self.formatter = formatter + self.setLevel(logging.DEBUG) + + def emit(self, record: logging.LogRecord) -> None: + print(self.format(record)) + + +# Stream handler +file_automation_logger.addHandler(FileAutomationLoggingHandler()) + + diff --git a/dev.toml b/dev.toml index 874e4c3..1c0f0e1 100644 --- a/dev.toml +++ b/dev.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "automation_file_dev" -version = "0.0.23" +version = "0.0.25" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ] diff --git a/pyproject.toml b/pyproject.toml index 6fe95f2..94a2b80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "automation_file" -version = "0.0.21" +version = "0.0.23" authors = [ { name = "JE-Chen", email = "zenmailman@gmail.com" }, ]