Files
baji-vc/scripts/update-gateway-manifest.py
T

20 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Refresh recoverable source hashes while preserving observed upstream provenance."""
from pathlib import Path
import hashlib,json,re
root=Path(__file__).resolve().parents[1]/'gateway'
manifest=json.loads((root/'SOURCE_MANIFEST.json').read_text())
manifest['code_version']=re.search(r"^VERSION = '([^']+)'",(root/'gateway.py').read_text(),re.M)[1]
for path in sorted(root.rglob('*')):
if not path.is_file():continue
name=path.relative_to(root).as_posix()
if name=='SOURCE_MANIFEST.json' or any(x in path.relative_to(root).parts for x in ('__pycache__','.runtime','models','logs')):continue
raw=path.read_bytes();digest=hashlib.sha256(raw).hexdigest();old=manifest['files'].get(name)
row={'source':old['source'] if old else 'workspace:gateway/'+name,'sha256':digest,'bytes':len(raw)}
if old and old['sha256']!=digest:
row['upstream_sha256']=old.get('upstream_sha256',old['sha256']);row['source']='workspace:gateway/'+name
elif old and 'upstream_sha256' in old:row['upstream_sha256']=old['upstream_sha256']
manifest['files'][name]=row
(root/'SOURCE_MANIFEST.json').write_text(json.dumps(manifest,indent=2,ensure_ascii=False)+'\n')
print('Updated canonical gateway source manifest')