You've already forked Funkciju-Specifikacijas-as-Code
Import UAPF package
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016igpMJBtapmG6vHE4vSF9q
29 lines
1016 B
Python
29 lines
1016 B
Python
"""Pārbauda specifikacijas/*.xml un veidne/*.xml pret schemas/specifikacija-0.1.xsd; ID unikāli; svaru summa 100."""
|
|
import glob
|
|
import sys
|
|
|
|
from lxml import etree
|
|
|
|
NS = "{urn:pppa:vpk:fspec:0.1}"
|
|
schema = etree.XMLSchema(etree.parse("schemas/specifikacija-0.1.xsd"))
|
|
ids, bad = set(), 0
|
|
for fn in sorted(glob.glob("veidne/*.xml") + glob.glob("specifikacijas/*.xml")):
|
|
doc = etree.parse(fn)
|
|
if not schema.validate(doc):
|
|
print(fn, schema.error_log.last_error)
|
|
bad += 1
|
|
continue
|
|
root = doc.getroot()
|
|
sid = root.get("id")
|
|
if fn.startswith("specifikacijas/"):
|
|
if sid in ids or not fn.endswith(sid + ".xml"):
|
|
print(fn, "ID nav unikāls vai neatbilst datnes nosaukumam:", sid)
|
|
bad += 1
|
|
ids.add(sid)
|
|
w = sum(float(k.get("svars")) for k in root.iter(NS + "Kritērijs"))
|
|
if abs(w - 100) > 0.01:
|
|
print(fn, "kritēriju svaru summa", w)
|
|
bad += 1
|
|
print("OK" if not bad else f"{bad} kļūdas")
|
|
sys.exit(1 if bad else 0)
|