| #!/usr/bin/env python3 | |
| """Regenerate the deterministic SHA-256 inventory for the staged package.""" | |
| from __future__ import annotations | |
| import hashlib | |
| from pathlib import Path | |
| EXCLUDED = { | |
| "audit_tmp.py", | |
| "metadata/checksums.sha256", | |
| "metadata/validation_run.json", | |
| } | |
| def sha256(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for chunk in iter(lambda: handle.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def main() -> int: | |
| root = Path(__file__).resolve().parents[1] | |
| paths = sorted( | |
| path for path in root.rglob("*") | |
| if path.is_file() | |
| and ".git" not in path.parts | |
| and "__pycache__" not in path.parts | |
| and path.relative_to(root).as_posix() not in EXCLUDED | |
| ) | |
| output = root / "metadata/checksums.sha256" | |
| output.write_text( | |
| "".join(f"{sha256(path)} {path.relative_to(root).as_posix()}\n" for path in paths), | |
| encoding="utf-8", | |
| ) | |
| print(f"wrote {len(paths)} checksums to {output}") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |