21 lines
768 B
Python
21 lines
768 B
Python
#!/usr/bin/env python3
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
root = Path(__file__).resolve().parents[1]
|
|
state_file = root / 'state/sync.json'
|
|
if not state_file.exists():
|
|
sys.exit('No OSV sync state')
|
|
state = json.loads(state_file.read_text())
|
|
for ecosystem, metadata in state.get('ecosystems', {}).items():
|
|
files = list((root / 'data' / ecosystem).glob('*.json'))
|
|
if len(files) < 1:
|
|
sys.exit(f'Empty ecosystem: {ecosystem}')
|
|
# Files are checked on import; spot-check retained data here to avoid reparsing millions.
|
|
for path in files[:10]:
|
|
item = json.loads(path.read_text())
|
|
if item.get('id') != path.stem:
|
|
sys.exit(f'Invalid {path}')
|
|
print(ecosystem, len(files), 'records')
|
|
print('Validation OK')
|