path objekte verwendet
This commit is contained in:
+17
-12
@@ -6,6 +6,7 @@ import sys
|
||||
import shutil
|
||||
import configparser
|
||||
from utils import check_environment_var, setup_logger
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_bbox(entities):
|
||||
@@ -188,9 +189,9 @@ def create_block_library(input_dir, output_file, config, logger=None):
|
||||
if error_files:
|
||||
print(f"Warnung: {len(error_files)} Dateien konnten nicht verarbeitet werden.")
|
||||
|
||||
output_dir = os.path.dirname(output_file)
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_dir = output_file.parent
|
||||
if not output_dir.exists():
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
doc.saveas(output_file)
|
||||
|
||||
@@ -233,26 +234,30 @@ if __name__ == "__main__":
|
||||
sys.exit(1)
|
||||
|
||||
# Verzeichnisse über Umgebungsvariablen oder Fallback
|
||||
INPUT_DIR = check_environment_var("PROJECT_WORK", ".")
|
||||
print(f"Verwende Input-Verzeichnis: {INPUT_DIR} \n")
|
||||
if args.input:
|
||||
INPUT_DIR = Path(args.input)
|
||||
print(f"Verwende Input-Verzeichnis: {INPUT_DIR} \n")
|
||||
else:
|
||||
INPUT_DIR = check_environment_var("PROJECT_WORK") / "converted_dxfs"
|
||||
print(f"Kein Input-Verzeichnis angegeben, verwende Standard: {INPUT_DIR} \n")
|
||||
|
||||
OUTPUT_FILE = os.path.join(check_environment_var("PROJECT_DATA", "."),"block_libaries", f"{args.name}.dxf")
|
||||
OUTPUT_FILE = check_environment_var("PROJECT_DATA") / "block_libaries" / f"{args.name}.dxf"
|
||||
|
||||
# Prüfe und erstelle log-Verzeichnis falls nötig
|
||||
log_dir = check_environment_var("PROJECT_LOG", ".")
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
log_dir = check_environment_var("PROJECT_LOG")
|
||||
if not log_dir.exists():
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
print(f"Log-Verzeichnis erstellt: {log_dir}")
|
||||
|
||||
# Logger Setup
|
||||
logger, log_file = setup_logger(log_dir, name='dxf2lib')
|
||||
logger = setup_logger(log_dir, name='dxf2lib')
|
||||
logger.info("=== DXF2LIB Verarbeitung gestartet ===")
|
||||
logger.info(f"Input-Verzeichnis: {INPUT_DIR}")
|
||||
logger.info(f"Output-Datei: {OUTPUT_FILE}")
|
||||
|
||||
# Lade Config-Datei
|
||||
config = configparser.ConfigParser()
|
||||
config_path = os.path.join(check_environment_var("PROJECT_CFG", "."), "allgemein.cfg")
|
||||
config_path = check_environment_var("PROJECT_CFG") / "allgemein.cfg"
|
||||
config.read(config_path, encoding="utf-8")
|
||||
logger.info(f"Config-Datei geladen: {config_path}")
|
||||
|
||||
@@ -263,7 +268,7 @@ if __name__ == "__main__":
|
||||
if not args.keep:
|
||||
logger.info(f"Keep-Argument nicht gesetzt, lösche Input-Verzeichnis: {INPUT_DIR}")
|
||||
try:
|
||||
if os.path.exists(INPUT_DIR):
|
||||
if INPUT_DIR.exists():
|
||||
shutil.rmtree(INPUT_DIR)
|
||||
logger.info(f"Verzeichnis '{INPUT_DIR}' wurde gelöscht.")
|
||||
except Exception as err:
|
||||
|
||||
Reference in New Issue
Block a user