from __future__ import annotations import argparse import hashlib import json from pathlib import Path def sha256(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(8 * 1024 * 1024), b""): digest.update(chunk) return digest.hexdigest() def main() -> None: parser = argparse.ArgumentParser(description="Verify a VidTouch release snapshot.") parser.add_argument("root", nargs="?", type=Path, default=Path(__file__).resolve().parents[1]) args = parser.parse_args() root = args.root.resolve() manifest = json.loads((root / "release_manifest.json").read_text(encoding="utf-8")) expected_stats = manifest["statistics"] actual_stats = { "fabrics": sum( 1 for line in (root / "label.txt").read_text(encoding="utf-8").splitlines() if line.strip() and not line.lstrip().startswith("#") ), "rgb_images": len(list((root / "RGBs").glob("*.jpg"))), "tactile_videos": len(list((root / "TACs").glob("*.mp4"))), } for key, value in actual_stats.items(): if expected_stats[key] != value: raise SystemExit(f"{key}: expected {expected_stats[key]}, found {value}") failures: list[str] = [] checked = 0 for line in (root / "checksums.sha256").read_text(encoding="utf-8").splitlines(): expected, relative = line.split(" ", 1) path = root / relative if not path.is_file(): failures.append(f"missing: {relative}") continue actual = sha256(path) checked += 1 if actual != expected: failures.append(f"checksum: {relative}") if failures: raise SystemExit("\n".join(failures)) print( f"VidTouch release verified: {actual_stats['fabrics']} fabrics, " f"{actual_stats['rgb_images']} RGB images, " f"{actual_stats['tactile_videos']} tactile videos, " f"{checked} checksums." ) if __name__ == "__main__": main()