BUGFIX: Annotations

This commit is contained in:
Simon Martens
2024-07-18 11:36:00 +02:00
parent ad10f37240
commit 12c9e45917
3 changed files with 38 additions and 55 deletions

View File

@@ -5,6 +5,7 @@ REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
XML_DIR = os.path.join(REPO_ROOT, 'XML')
def validate_xml(xml_file):
errors = []
try:
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(xml_file, parser)
@@ -21,38 +22,37 @@ def validate_xml(xml_file):
schema.assertValid(tree)
print(f"Validation erfolgreich: {xml_file}")
else:
print(f"Schema-Datei nicht gefunden: {xsd_path} für {xml_file}")
return False
errors.append(f"Schema-Datei nicht gefunden: {xsd_path} für {xml_file}")
else:
print(f"Keine Schema-Location gefunden in {xml_file}")
return False
errors.append(f"Keine Schema-Location gefunden in {xml_file}")
except etree.DocumentInvalid as e:
print(f"Validierungsfehler in {xml_file}:")
errors.append(f"Validierungsfehler in {xml_file}:")
for error in e.error_log:
print(f" Zeile {error.line}, Spalte {error.column}: {error.message}")
return False
errors.append(f" Zeile {error.line}, Spalte {error.column}: {error.message}")
except etree.XMLSyntaxError as e:
print(f"XML-Syntaxfehler in {xml_file}:")
print(f" Zeile {e.lineno}, Spalte {e.offset}: {e.msg}")
return False
errors.append(f"XML-Syntaxfehler in {xml_file}:")
errors.append(f" Zeile {e.lineno}, Spalte {e.offset}: {e.msg}")
except Exception as e:
print(f"Fehler bei der Verarbeitung von {xml_file}: {str(e)}")
return False
errors.append(f"Fehler bei der Verarbeitung von {xml_file}: {str(e)}")
return True
return errors
def main():
validation_failed = False
all_errors = []
for root, dirs, files in os.walk(XML_DIR):
for file in files:
if file.endswith('.xml'):
xml_file = os.path.join(root, file)
if not validate_xml(xml_file):
validation_failed = True
errors = validate_xml(xml_file)
all_errors.extend(errors)
if validation_failed:
print("Validierung fehlgeschlagen. Bitte korrigieren Sie die oben genannten Fehler.")
if all_errors:
print("Validierung fehlgeschlagen. Bitte korrigieren Sie die folgenden Fehler:")
with open('schema_validation_errors.txt', 'w') as f:
for error in all_errors:
print(error)
f.write(f"{error}\n")
exit(1)
else:
print("Alle XML-Dateien wurden erfolgreich validiert.")