From 90859715c4bd083104dc2bd62eeb36378464c360 Mon Sep 17 00:00:00 2001 From: Max P Date: Sat, 26 Apr 2025 16:18:29 +0000 Subject: [PATCH] Enhances directory management with improved messaging Replaces print statements with a ConsoleUtils helper for consistent, customizable output. Adds a new `clear_build_directories` function to exclude specific directories from deletion. Changes default behavior of `silent` parameter to `False` for better visibility. Improves code readability and user feedback. --- src/utils/directory_manager.py | 48 +++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/utils/directory_manager.py b/src/utils/directory_manager.py index 90a3719..92a3003 100644 --- a/src/utils/directory_manager.py +++ b/src/utils/directory_manager.py @@ -1,29 +1,57 @@ import os import shutil from models.config import DIRECTORIES +from utils.console_utils import ConsoleUtils -def ensure_directories_exist(silent: bool = True): +def ensure_directories_exist(silent: bool = False): """ Erstellt alle in der Konfiguration definierten Verzeichnisse, falls sie nicht existieren. """ + console_utils = None + if not silent: + console_utils = ConsoleUtils("hdlbuild") + for name, path in DIRECTORIES.dict().items(): if not os.path.exists(path): os.makedirs(path, exist_ok=True) - if not silent: - print(f"[hdlbuild] Verzeichnis erstellt: {path}") + if not silent and console_utils: + console_utils.print(f"Verzeichnis erstellt: {path}") else: - if not silent: - print(f"[hdlbuild] Verzeichnis vorhanden: {path}") + if not silent and console_utils: + console_utils.print(f"[hdlbuild] Verzeichnis vorhanden: {path}") -def clear_directories(silent: bool = True): +def clear_directories(silent: bool = False): """ Löscht alle in der Konfiguration definierten Verzeichnisse, falls sie existieren. """ + console_utils = None + if not silent: + console_utils = ConsoleUtils("hdlbuild") + for name, path in DIRECTORIES.dict().items(): if os.path.exists(path): - if not silent: - print(f"[hdlbuild] Lösche Verzeichnis: {path}") + if not silent and console_utils: + console_utils.print(f"Lösche Verzeichnis: {path}") shutil.rmtree(path) else: - if not silent: - print(f"[hdlbuild] Verzeichnis nicht vorhanden, übersprungen: {path}") + if not silent and console_utils: + console_utils.print(f"Verzeichnis nicht vorhanden, übersprungen: {path}") + +def clear_build_directories(silent: bool = False): + """ + Löscht alle in der Konfiguration definierten Verzeichnisse, falls sie existieren. + """ + console_utils = None + if not silent: + console_utils = ConsoleUtils("hdlbuild") + + for name, path in DIRECTORIES.dict().items(): + if name == "dependency": + continue + if os.path.exists(path): + if not silent and console_utils: + console_utils.print(f"Lösche Verzeichnis: {path}") + shutil.rmtree(path) + else: + if not silent and console_utils: + console_utils.print(f"Verzeichnis nicht vorhanden, übersprungen: {path}")