Validierungs-Logik implementiert, welche die gegebenen Configs auf Konsistenz prüft
This commit is contained in:
@@ -418,6 +418,43 @@ def dxf_is_binary(dxf_path):
|
||||
header = f.read(22)
|
||||
return b'AutoCAD Binary DXF' in header
|
||||
|
||||
def validate_configs():
|
||||
errors= []
|
||||
|
||||
print("Validating given configs: Checking for inconsistency.")
|
||||
|
||||
# 1. Alle Prefixes aus Routing_include müssen in Cable_Mapping stehen (nur BMK.cfg)
|
||||
if config_BMK.has_section("Routing-Include") and config_BMK.has_section("Cable-Mapping"):
|
||||
for prefix in config_BMK.options("Routing-Include"):
|
||||
if prefix not in config_BMK["Cable-Mapping"]:
|
||||
errors.append(f"No Cable-Mapping for Prefix '{prefix}' within 'Routing-Include'")
|
||||
|
||||
# 2. Jeder Eintrag in Cable-Mapping → Sektionen in kabel.cfg prüfen (Abgleich BMK.cfg und kabel.cfg)
|
||||
if config_BMK.has_section("Cable-Mapping"):
|
||||
for mapping_key, value in config_BMK.items("Cable-Mapping"):
|
||||
sections = [s.strip() for s in value.split(",")]
|
||||
for section in sections:
|
||||
if not config_cables.has_section(section):
|
||||
errors.append(f"Cable-Section '{section}' from Cable-Mapping ({mapping_key}) missing in kabel.cfg")
|
||||
|
||||
# 3. Länge in Length-Adjustments muss float >= 0 sein
|
||||
if config_BMK.has_section("Length-Adjustments"):
|
||||
for prefix, value in config_BMK.items("Length-Adjustments"):
|
||||
try:
|
||||
f = float(value)
|
||||
if f < 0:
|
||||
errors.append(f"Negative Value in Length-Adjustments for {prefix}: {value}")
|
||||
except ValueError:
|
||||
errors.append(f"Invalid Value in Length-Adjustments for {prefix}: {value}")
|
||||
|
||||
if errors:
|
||||
print("Inconsistencies found:")
|
||||
for e in errors:
|
||||
print(f"- {e}")
|
||||
print("continuing")
|
||||
else:
|
||||
print ("No inconsistencies found")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='fetches the x/y positions from a dxf file', prog='getpositions')
|
||||
@@ -463,6 +500,13 @@ if __name__ == '__main__':
|
||||
config_BMK = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
|
||||
config_BMK.optionxform = lambda option: option # preserve case for letters
|
||||
config_BMK.read(os.path.join(config_dir, "BMK.cfg"))
|
||||
|
||||
# Kabel-Config laden
|
||||
config_cables = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
|
||||
config_cables.optionxform = lambda option: option
|
||||
config_cables.read(os.path.join(config_dir, "kabel.cfg"))
|
||||
|
||||
validate_configs()
|
||||
|
||||
output_results = dict()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user