Datasets:
File size: 1,163 Bytes
1788f61 | 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 | #!/usr/bin/env python3
"""Hash every materialized source file for an auditable release manifest."""
from __future__ import annotations
import argparse
import hashlib
from pathlib import Path
def sha256(path: Path) -> str:
h = hashlib.sha256()
with path.open("rb") as f:
for block in iter(lambda: f.read(8 * 1024 * 1024), b""):
h.update(block)
return h.hexdigest()
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--source-root", type=Path, required=True)
ap.add_argument("--release-root", type=Path, required=True)
args = ap.parse_args()
source = args.source_root.resolve()
paths = sorted(
p for split in ("training", "validation")
for p in (source / split).rglob("*")
if p.is_file()
)
output = args.release_root / "SOURCE_FILES.sha256"
with output.open("w", encoding="utf-8") as f:
for path in paths:
rel = path.relative_to(source).as_posix()
f.write(f"{sha256(path)} {rel}\n")
print(f"wrote {len(paths)} source-file hashes to {output}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|