CARLA-MWRS / scripts /write_source_hashes.py
PeterNano's picture
Add CARLA-MWRS v1.0.0 metadata and verification tools
1788f61 verified
Raw
History Blame Contribute Delete
1.16 kB
#!/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())