File size: 971 Bytes
3c57262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3
"""Offline integrity check for one exported benchmark bundle."""
from __future__ import annotations
import hashlib, json, pathlib, sys
root = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else '.').resolve()
manifest = root / 'MANIFEST.json'
if not manifest.is_file(): raise SystemExit(f'missing {manifest}')
data = json.loads(manifest.read_text())
errors=[]; checked=0
for row in data.get('checksums', []):
    p=root / row['path']
    if not p.is_file(): errors.append(f'missing {row["path"]}'); continue
    h=hashlib.sha256()
    with p.open('rb') as f:
        for chunk in iter(lambda:f.read(8*1024*1024), b''): h.update(chunk)
    checked+=1
    if h.hexdigest()!=row['sha256']: errors.append(f'hash mismatch {row["path"]}')
if errors:
    print('\n'.join(errors), file=sys.stderr); raise SystemExit(1)
print(json.dumps({'status':'passed','benchmark':data.get('benchmark'),'checksums_checked':checked,'root':str(root)}, ensure_ascii=False))