File size: 2,063 Bytes
299146f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()