File size: 1,138 Bytes
e5277d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #!/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())
|