You've already forked Informacijas-sistemas-as-Code
Import UAPF package
Pilotiestādes: Valsts meža dienests (pakalpojums -> darbs, sistēma, informācijas resurss; sistēma -> resurss) un Latvijas Nacionālā bibliotēka. Katru saiti pārbaudīja Claude pret nolikuma formulējumu un VIRSIS aprakstu; pierādījuma līmenis direct vai broad. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016679RwmHsuTFfxt26wP6rk
56 lines
2.5 KiB
Python
56 lines
2.5 KiB
Python
"""Pārbauda sasaistes/*.xml:
|
|
- atbilst XSD sasaistes-0.1.xsd (saites unikālas);
|
|
- datnes nosaukums ir iestādes VPK ID (atribūts institution);
|
|
- saite sākas ar šī repozitorija objektu (FROM_TYPE);
|
|
- attiecība der abiem galiem (implements -> fdk; supported_by -> information_system; uses -> information_resource;
|
|
maintains: information_system -> information_resource; same_as -> arch);
|
|
- fdk ieraksts pieder tai pašai iestādei.
|
|
Vai objekti (VIRSIS ID, B22 ieraksti) tiešām eksistē, pārbauda VDE ielādes laikā (pārbaude confirmed_link_resolves).
|
|
|
|
Lietošana: python3 tools/validate_links.py
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from lxml import etree
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
FROM_TYPE = "information_system"
|
|
NS = {"s": "urn:pppa:vpk:sasaistes:0.1"}
|
|
ALLOWED = {"implements": ({"service"}, {"fdk"}), "supported_by": ({"service"}, {"information_system"}),
|
|
"uses": ({"service"}, {"information_resource"}), "maintains": ({"information_system"}, {"information_resource"}),
|
|
"same_as": ({"service", "information_system", "information_resource"}, {"arch"})}
|
|
|
|
|
|
def check(folder):
|
|
errors, n = [], 0
|
|
schema = etree.XMLSchema(etree.parse(str(ROOT / "sasaistes-0.1.xsd")))
|
|
for f in sorted(folder.glob("*.xml")):
|
|
doc = etree.parse(str(f))
|
|
if not schema.validate(doc):
|
|
errors += [f"{f.name}: XSD {e.message} (rinda {e.line})" for e in schema.error_log]
|
|
continue
|
|
inst = doc.getroot().get("institution")
|
|
if f.stem != inst:
|
|
errors.append(f"{f.name}: datnes nosaukumam jābūt {inst}.xml")
|
|
for el in doc.getroot().findall("s:Link", NS):
|
|
n += 1
|
|
ft, fid = el.get("from").split(":", 1)
|
|
tt, tid = el.get("to").split(":", 1)
|
|
rel = el.get("relation")
|
|
if ft != FROM_TYPE:
|
|
errors.append(f"{f.name}: {el.get('from')} — šajā repozitorijā saites sākas ar {FROM_TYPE}")
|
|
if ft not in ALLOWED[rel][0] or tt not in ALLOWED[rel][1]:
|
|
errors.append(f"{f.name}: {rel} neder {ft} -> {tt}")
|
|
if tt == "fdk" and tid[2:9] != inst:
|
|
errors.append(f"{f.name}: {tid} nav iestādes {inst} ieraksts")
|
|
return errors, n
|
|
|
|
|
|
if __name__ == "__main__":
|
|
errs, n = check(Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "sasaistes")
|
|
for e in errs:
|
|
print("E ", e)
|
|
print(f"I {n} saites\n\n{len(errs)} kļūdas")
|
|
sys.exit(1 if errs else 0)
|