74b08e31c7
- icons.py: _ICON_MAP entfernt (war reine Identitätsabbildung), Pfad wird direkt aus dem Namen abgeleitet - icons.py: Render-Cache mit Schlüssel (name, theme-farbe) ergänzt, vermeidet wiederholtes SVG-Rendering bei Baum-/Kontextmenü-Aufbau - icons.py: Qt-Ressourcen-Registrierung gekapselt (Import aus main.py hierher verschoben) - download_icons.py: toten folder-open-Eintrag entfernt (in Feather nicht vorhanden, nirgends genutzt) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
3.8 KiB
Python
125 lines
3.8 KiB
Python
import sys
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from PySide6.QtGui import QIcon
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
from ui.MainWindow import MainWindow
|
|
from ui.AppSettings import AppSettingsDlg
|
|
from conf import app_settings
|
|
|
|
|
|
def cleanup_old_logs(log_dir, max_age_hours=24):
|
|
"""
|
|
Löscht Log-Dateien, die älter als die angegebene Anzahl von Stunden sind.
|
|
|
|
Args:
|
|
log_dir: Pfad zum Log-Verzeichnis
|
|
max_age_hours: Maximales Alter der Log-Dateien in Stunden (Standard: 24)
|
|
"""
|
|
import time
|
|
|
|
if not log_dir.exists():
|
|
return
|
|
|
|
cutoff_time = time.time() - (max_age_hours * 3600)
|
|
deleted_count = 0
|
|
|
|
# Alle .log Dateien im Verzeichnis durchsuchen
|
|
for log_file in log_dir.glob("*.log"):
|
|
try:
|
|
# Änderungszeit der Datei abrufen
|
|
file_mtime = log_file.stat().st_mtime
|
|
|
|
# Wenn die Datei älter als die Grenzzeit ist, löschen
|
|
if file_mtime < cutoff_time:
|
|
log_file.unlink()
|
|
deleted_count += 1
|
|
except Exception as e:
|
|
logging.warning(f"Fehler beim Löschen von {log_file}: {e}")
|
|
|
|
if deleted_count > 0:
|
|
logging.info(f"{deleted_count} alte Log-Datei(en) gelöscht (älter als {max_age_hours} Stunden)")
|
|
|
|
|
|
def main():
|
|
"""Haupteinstiegspunkt der Anwendung."""
|
|
# Logging konfigurieren - sowohl Datei als auch Konsole
|
|
from datetime import datetime
|
|
|
|
# Log-Verzeichnis erstellen (im selben Verzeichnis wie config.json)
|
|
from conf import config_path
|
|
|
|
log_dir = config_path.parent / "logs"
|
|
log_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Log-Dateiname mit Timestamp
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
log_file = log_dir / f"documentor_{timestamp}.log"
|
|
|
|
# Root-Logger konfigurieren
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
# Formatter für alle Handler
|
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%H:%M:%S")
|
|
|
|
# Handler 1: Datei (alles ab DEBUG)
|
|
file_handler = logging.FileHandler(log_file, encoding="utf-8")
|
|
file_handler.setLevel(logging.DEBUG)
|
|
file_handler.setFormatter(formatter)
|
|
logger.addHandler(file_handler)
|
|
|
|
# Handler 2: Konsole (alles ab INFO)
|
|
console_handler = logging.StreamHandler(sys.stdout)
|
|
console_handler.setLevel(logging.INFO)
|
|
console_handler.setFormatter(formatter)
|
|
logger.addHandler(console_handler)
|
|
|
|
logging.info(f"Logging initialisiert: {log_file}")
|
|
|
|
# Alte Log-Dateien aufräumen (erst nach Logger-Init)
|
|
cleanup_old_logs(log_dir, max_age_hours=24)
|
|
|
|
# Unter Windows: AppUserModelID setzen, damit die Taskleiste das richtige Symbol zeigt
|
|
if sys.platform == "win32":
|
|
import ctypes
|
|
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("de.vitaligraf.documentor")
|
|
|
|
# QApplication-Instanz erstellen
|
|
app = QApplication(sys.argv)
|
|
|
|
# App-Symbol setzen (PyInstaller: sys._MEIPASS, sonst Quellpfad)
|
|
if getattr(sys, "frozen", False):
|
|
icon_path = Path(sys._MEIPASS) / "resources" / "icon.ico"
|
|
else:
|
|
icon_path = Path(__file__).parent.parent / "resources" / "icon.ico"
|
|
if icon_path.exists():
|
|
app.setWindowIcon(QIcon(str(icon_path)))
|
|
|
|
# Hauptfenster erstellen
|
|
window = MainWindow()
|
|
|
|
# Hauptfenster anzeigen
|
|
window.show()
|
|
|
|
if (
|
|
len(app_settings.apache_fops) == 0
|
|
or len(app_settings.diff_pdfs) == 0
|
|
or len(app_settings.java_vms) == 0
|
|
or len(app_settings.saxon_jars) == 0
|
|
or len(app_settings.xsl_dirs) == 0
|
|
or len(app_settings.pdf_projects) == 0
|
|
):
|
|
# Als Modal Dialog öffnen!
|
|
dlg = AppSettingsDlg(window, app_settings)
|
|
dlg.exec()
|
|
|
|
# Anwendung ausführen und Rückgabewert zurückgeben
|
|
return app.exec()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|