24 lines
923 B
Python
24 lines
923 B
Python
#!/usr/bin/env python3
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
index = root / 'data/index/updates.json'
|
|
if not index.is_file():
|
|
raise SystemExit('Missing data/index/updates.json')
|
|
obj = json.loads(index.read_text())
|
|
rows = obj if isinstance(obj, list) else obj.get('value')
|
|
if not isinstance(rows, list) or not rows:
|
|
raise SystemExit('Empty or invalid updates index')
|
|
files = list((root/'data/cvrf').glob('*/*.json'))
|
|
if not files:
|
|
raise SystemExit('No CVRF documents present')
|
|
for f in files:
|
|
if not re.fullmatch(r'\d{4}-[A-Za-z]{3}\.json', f.name) or f.parent.name != f.name[:4]:
|
|
raise SystemExit(f'Unexpected file path: {f}')
|
|
document = json.loads(f.read_text())
|
|
if not isinstance(document, dict) or not document:
|
|
raise SystemExit(f'Invalid document {f}')
|
|
print(f'OK: {len(rows)} index entries and {len(files)} CVRF JSON files')
|