| #!/usr/bin/env python3 | |
| from pathlib import Path | |
| import hashlib | |
| ROOT = Path(__file__).resolve().parent | |
| MANIFEST = ROOT / "BUNDLE_SHA256SUMS.txt" | |
| def digest(path: Path) -> str: | |
| return hashlib.sha256(path.read_bytes()).hexdigest() | |
| files = sorted( | |
| path for path in ROOT.rglob("*") | |
| if path.is_file() and path != MANIFEST and "__pycache__" not in path.parts | |
| ) | |
| MANIFEST.write_text( | |
| "\n".join(f"{digest(path)} ./{path.relative_to(ROOT).as_posix()}" for path in files) + "\n", | |
| encoding="utf-8", | |
| ) | |
| assert all( | |
| digest(ROOT / line.split(" ./", 1)[1]) == line.split(" ./", 1)[0] | |
| for line in MANIFEST.read_text(encoding="utf-8").splitlines() | |
| ) | |
| print(f"manifest verified: {len(files)} files") | |