Refactor: Code-Duplikation reduziert und Dead Code entfernt
- blake2b-Hash-Berechnung in zentrale Utility-Funktion extrahiert (src/utils.py) mit chunk-basiertem Hashing für bessere RAM-Effizienz - _transform_all_xml_files und _transform_all_xml_files_force zu einer Methode mit force-Parameter zusammengeführt - Project-Lookup-Methoden (getXsl, getJavaVm, etc.) über gemeinsame _lookup()-Hilfsmethode konsolidiert - Duplizierte XML-Sammel-Methoden entfernt, Set-basierte Duplikatsprüfung eingeführt - Ungenutzte Imports, Dead Code und wirkungslose Ausdrücke entfernt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+5
-44
@@ -7,16 +7,14 @@ Dieses Modul enthält alle QThread-Klassen, die für Hintergrundoperationen verw
|
||||
- TransformationThread: Ausführung von XSL-Transformationen
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from PySide6.QtCore import QThread, Signal
|
||||
|
||||
from conf import TreeNode, XslFile, XmlFile
|
||||
from transform import TransformationJob
|
||||
from utils import calculate_blake2b_hash
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -32,7 +30,7 @@ class XmlHashCalculatorThread(QThread):
|
||||
calculation_finished = Signal(int, int) # processed_count, total_count
|
||||
error_occurred = Signal(str, str) # xml_file_path, error_message
|
||||
|
||||
def __init__(self, project_dir: Path, xml_files: List[XmlFile]):
|
||||
def __init__(self, project_dir: Path, xml_files: list[XmlFile]):
|
||||
"""
|
||||
Initialisiert den Hash-Berechnungs-Thread.
|
||||
|
||||
@@ -81,32 +79,8 @@ class XmlHashCalculatorThread(QThread):
|
||||
logger.info(f"Hash-Berechnung abgeschlossen: {self.processed_count}/{len(self.xml_files)} verarbeitet")
|
||||
|
||||
def _calculate_blake2b_hash(self, file_path: Path) -> str | None:
|
||||
"""
|
||||
Berechnet den blake2b-Hash einer XML-Datei.
|
||||
|
||||
Args:
|
||||
file_path: Pfad zur XML-Datei
|
||||
|
||||
Returns:
|
||||
str: Hash-Wert mit "blake2b:" Präfix oder None bei Fehler
|
||||
"""
|
||||
try:
|
||||
if not file_path.exists():
|
||||
logger.warning(f"XML-Datei nicht gefunden: {file_path}")
|
||||
return None
|
||||
|
||||
# Datei binär lesen und Hash berechnen
|
||||
with open(file_path, "rb") as f:
|
||||
file_content = f.read()
|
||||
hash_obj = hashlib.blake2b(file_content)
|
||||
hash_hex = hash_obj.hexdigest()
|
||||
|
||||
# Präfix hinzufügen
|
||||
return f"blake2b:{hash_hex}"
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler beim Berechnen des Hash für {file_path}: {e}")
|
||||
return None
|
||||
"""Berechnet den blake2b-Hash einer XML-Datei."""
|
||||
return calculate_blake2b_hash(file_path)
|
||||
|
||||
|
||||
class XmlBatchProcessingThread(QThread):
|
||||
@@ -217,20 +191,7 @@ class XmlBatchProcessingThread(QThread):
|
||||
|
||||
def _calculate_hash_for_file(self, file_path: Path) -> str | None:
|
||||
"""Berechnet blake2b Hash für eine Datei."""
|
||||
try:
|
||||
if not file_path.exists():
|
||||
return None
|
||||
|
||||
with open(file_path, "rb") as f:
|
||||
file_content = f.read()
|
||||
hash_obj = hashlib.blake2b(file_content)
|
||||
hash_hex = hash_obj.hexdigest()
|
||||
|
||||
return f"blake2b:{hash_hex}"
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Fehler beim Berechnen des Hash für {file_path}: {e}")
|
||||
return None
|
||||
return calculate_blake2b_hash(file_path)
|
||||
|
||||
def _find_xml_file_by_hash(self, hash_value: str) -> XmlFile | None:
|
||||
"""Sucht eine XML-Datei anhand ihres Hash-Werts."""
|
||||
|
||||
Reference in New Issue
Block a user