update file sourcing

This commit is contained in:
Christoph Brandau
2025-08-05 18:18:17 +02:00
parent 1abf89fe56
commit b680c01989
3 changed files with 81 additions and 23 deletions
+21 -4
View File
@@ -1,22 +1,23 @@
import xml.etree.ElementTree as ET
from dataclasses import dataclass
from typing import List, Optional
from pathlib import Path
@dataclass
class SourcedFiles:
class SourcedFile:
layer_name: str
subfolder: Optional[str]
files: List[str]
def read_psc_file(psc_file: str) -> List[SourcedFiles]:
def read_psc_file(psc_file: Path) -> List[SourcedFile]:
tree = ET.parse(psc_file)
root = tree.getroot()
layers = root.findall(".//Layer")
layer_info_list: List[SourcedFiles] = []
layer_info_list: List[SourcedFile] = []
for layer in layers:
layer_name = layer.attrib.get("Name")
subfolder = layer.attrib.get("SubFolder")
@@ -30,6 +31,22 @@ def read_psc_file(psc_file: str) -> List[SourcedFiles]:
script_names.append(name)
layer_info_list.append(
SourcedFiles(layer_name=layer_name, subfolder=subfolder, files=script_names)
SourcedFile(layer_name=layer_name, subfolder=subfolder, files=script_names)
)
return layer_info_list
def get_all_psc_files(root_path: Path) -> list[Path]:
"""Sammelt alle .tcl-Dateien rekursiv im gegebenen Verzeichnis"""
return [path for path in root_path.rglob("*.psc")]
if __name__ == "__main__":
test = get_all_psc_files(
Path(
r"H:\janus-engineering-customers\KSB_Frankenthal\custom\library\machine\installed_machines\ksb_pe_grob_g550_sone\postprocessor"
)
)
print(test)
for pp in test:
read_psc_file(pp)