Skip to content

Commit a61b20f

Browse files
committed
add tallele_setup for configuration and logging
1 parent ff1f30e commit a61b20f

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

CollagePDFMaker.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
from talelle_setup import Path, TALELLE_DIR, config_log
2+
TALELLE_TOOL = Path(__file__).stem
3+
config_log(TALELLE_TOOL)
4+
15
import sys
26
import os
37
import json
48
import datetime
59
import placement
10+
11+
import logging
612
from PySide6.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
713
QLineEdit, QFileDialog, QComboBox, QMessageBox, QProgressBar)
814
from PySide6.QtCore import Qt, QThread, Signal
915
from PySide6.QtGui import QPixmap
1016

17+
logger = logging.getLogger(__name__)
18+
logger.info(f'{TALELLE_TOOL} started')
19+
1120

1221
class PDFCreatorThread(QThread):
1322
creationStarted = Signal()
@@ -63,9 +72,7 @@ def __init__(self):
6372

6473
@staticmethod
6574
def get_settings_file():
66-
home_dir = os.path.expanduser("~")
67-
filename = "CollagePDFMaker.json"
68-
return os.path.join(home_dir, filename)
75+
return os.path.join(TALELLE_DIR, f'{TALELLE_TOOL}.json')
6976

7077
def save_settings(self, language, maxWidth="", maxHeight="", margin=""):
7178
settings = {

logging.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[loggers]
2+
keys=root
3+
4+
[handlers]
5+
keys=rotatingFileHandler
6+
7+
[formatters]
8+
keys=simpleFormatter
9+
10+
[logger_root]
11+
level=DEBUG
12+
handlers=rotatingFileHandler
13+
14+
15+
[handler_rotatingFileHandler]
16+
class=logging.handlers.RotatingFileHandler
17+
level=DEBUG
18+
formatter=simpleFormatter
19+
args=("%(log_path)s", "a", 1024, 4, "utf-8")
20+
21+
[formatter_simpleFormatter]
22+
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s

talelle_setup.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import logging
2+
import logging.config
3+
4+
import os
5+
import shutil
6+
from pathlib import Path
7+
8+
def to_path(path: str) -> Path:
9+
return Path(path)
10+
11+
TALELLE_DIR = os.path.join(os.path.expanduser('~'), 'TalelleApps')
12+
to_path(TALELLE_DIR).mkdir(parents=True, exist_ok=True)
13+
14+
15+
def config_log(talelle_tool: str):
16+
log_conf_name = 'logging.conf'
17+
local_log_conf = f'./{log_conf_name}'
18+
19+
log_conf = os.path.join(TALELLE_DIR, local_log_conf)
20+
log_file = os.path.join(TALELLE_DIR, f'{talelle_tool}.log')
21+
22+
if not os.path.exists(log_conf):
23+
shutil.copy(local_log_conf, log_conf)
24+
25+
logging.config.fileConfig(log_conf, defaults={"log_path": log_file})

0 commit comments

Comments
 (0)