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.
This commit is contained in:
@@ -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}")
|
||||
|
Reference in New Issue
Block a user