Skip to content

Commit 93e87fb

Browse files
authored
Merge pull request #38 from Integration-Automation/dev
Dev
2 parents ecbbdeb + b78aef2 commit 93e87fb

File tree

8 files changed

+96
-15
lines changed

8 files changed

+96
-15
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

automation_file/gui/__init__.py

Whitespace-only changes.

automation_file/gui/main_widget.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from je_auto_control.gui.main_window import AutoControlGUI
7+
8+
from PySide6.QtWidgets import QWidget, QGridLayout
9+
10+
11+
class AutoControlWidget(QWidget):
12+
13+
def __init__(self, main_ui: AutoControlGUI):
14+
super().__init__()
15+
# Variable
16+
self.main_ui = main_ui
17+
# UI component
18+
# Grid layout
19+
self.grid_layout = QGridLayout()
20+
self.setLayout(self.grid_layout)

automation_file/gui/main_window.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import sys
3+
from pathlib import Path
4+
5+
from PySide6.QtCore import QCoreApplication, QTimer
6+
from PySide6.QtGui import QIcon
7+
from PySide6.QtWidgets import QMainWindow, QApplication
8+
from qt_material import apply_stylesheet
9+
10+
from je_auto_control.gui.main_widget import AutoControlWidget
11+
12+
13+
class AutoControlGUI(QMainWindow):
14+
15+
def __init__(self, debug_mode: bool = False):
16+
super().__init__()
17+
self.debug_mode = debug_mode
18+
self.central_widget = AutoControlWidget(self)
19+
self.setCentralWidget(self.central_widget)
20+
self.setWindowTitle("AutoControlGUI")
21+
# Set Icon
22+
self.icon_path = Path(os.getcwd() + "/je_driver_icon.ico")
23+
self.icon = QIcon(str(self.icon_path))
24+
if self.icon.isNull() is False:
25+
self.setWindowIcon(self.icon)
26+
if self.debug_mode:
27+
close_timer = QTimer(self)
28+
close_timer.setInterval(10000)
29+
close_timer.timeout.connect(self.debug_close)
30+
close_timer.start()
31+
32+
@classmethod
33+
def debug_close(cls):
34+
sys.exit(0)
35+
36+
37+
def start_autocontrol_gui(debug_mode: bool = False) -> None:
38+
autocontrol_gui = QCoreApplication.instance()
39+
if autocontrol_gui is None:
40+
autocontrol_gui = QApplication(sys.argv)
41+
window = AutoControlGUI(debug_mode)
42+
apply_stylesheet(autocontrol_gui, theme='dark_amber.xml')
43+
window.showMaximized()
44+
sys.exit(autocontrol_gui.exec())

automation_file/local/file/file_process.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
from automation_file.utils.logging.loggin_instance import file_automation_logger
77

88

9-
def copy_file(file_path: str, target_path: str) -> bool:
9+
def copy_file(file_path: str, target_path: str, copy_metadata: bool = True) -> bool:
1010
"""
1111
:param file_path: which file do we want to copy (str path)
1212
:param target_path: put copy file on target path
13+
:param copy_metadata: copy file metadata or not
1314
:return: True if success else False
1415
"""
1516
file_path = Path(file_path)
1617
if file_path.is_file() and file_path.exists():
1718
try:
18-
shutil.copy2(file_path, target_path)
19+
if copy_metadata:
20+
shutil.copy2(file_path, target_path)
21+
else:
22+
shutil.copy(file_path, target_path)
1923
file_automation_logger.info(f"Copy file origin path: {file_path}, target path : {target_path}")
2024
return True
2125
except shutil.Error as error:
@@ -25,17 +29,19 @@ def copy_file(file_path: str, target_path: str) -> bool:
2529
return False
2630

2731

28-
def copy_specify_extension_file(file_dir_path: str, target_extension: str, target_path: str) -> bool:
32+
def copy_specify_extension_file(
33+
file_dir_path: str, target_extension: str, target_path: str, copy_metadata: bool = True) -> bool:
2934
"""
3035
:param file_dir_path: which dir do we want to search
3136
:param target_extension: what extension we will search
3237
:param target_path: copy file to target path
38+
:param copy_metadata: copy file metadata or not
3339
:return: True if success else False
3440
"""
3541
file_dir_path = Path(file_dir_path)
3642
if file_dir_path.exists() and file_dir_path.is_dir():
3743
for file in file_dir_path.glob(f"**/*.{target_extension}"):
38-
copy_file(str(file), target_path)
44+
copy_file(str(file), target_path, copy_metadata=copy_metadata)
3945
file_automation_logger.info(
4046
f"Copy specify extension file on dir"
4147
f"origin dir path: {file_dir_path}, target extension: {target_extension}, "
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import logging
2-
import sys
32

3+
logging.root.setLevel(logging.DEBUG)
44
file_automation_logger = logging.getLogger("File Automation")
5-
file_automation_logger.setLevel(logging.INFO)
65
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)
126
# File handler
13-
file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w+")
7+
file_handler = logging.FileHandler(filename="FileAutomation.log", mode="w")
148
file_handler.setFormatter(formatter)
159
file_automation_logger.addHandler(file_handler)
1610

11+
class FileAutomationLoggingHandler(logging.Handler):
12+
13+
# redirect logging stderr output to queue
14+
15+
def __init__(self):
16+
super().__init__()
17+
self.formatter = formatter
18+
self.setLevel(logging.DEBUG)
19+
20+
def emit(self, record: logging.LogRecord) -> None:
21+
print(self.format(record))
22+
23+
24+
# Stream handler
25+
file_automation_logger.addHandler(FileAutomationLoggingHandler())
26+
27+

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.23"
9+
version = "0.0.25"
1010
authors = [
1111
{ name = "JE-Chen", email = "[email protected]" },
1212
]

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.21"
9+
version = "0.0.23"
1010
authors = [
1111
{ name = "JE-Chen", email = "[email protected]" },
1212
]

0 commit comments

Comments
 (0)