| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import hashlib | |
| from pathlib import Path | |
| import subprocess | |
| ROOT = Path(__file__).resolve().parent | |
| OUT = ROOT / "BUNDLE_SHA256SUMS.txt" | |
| def digest(path: Path) -> str: | |
| h = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for block in iter(lambda: handle.read(1 << 20), b""): | |
| h.update(block) | |
| return h.hexdigest() | |
| rows = [] | |
| tracked = subprocess.check_output(["git", "ls-files", "-z"], cwd=ROOT) | |
| for name in sorted(x for x in tracked.decode().split("\0") if x): | |
| path = ROOT / name | |
| if path.is_file() and path != OUT: | |
| rows.append(f"{digest(path)} {path.relative_to(ROOT).as_posix()}") | |
| OUT.write_text("\n".join(rows) + "\n", encoding="utf-8") | |
| print(f"wrote {len(rows)} entries to {OUT.name}") | |