latenarray-i2ce-data / join_full_pool.py
chironYu's picture
join_full_pool.py writes full_pool_READY; the card names the packaged download
9984d35 verified
Raw History Blame Contribute Delete
1.31 kB
"""Rebuild full_pool_fp16.npy from its parts and check it against SHA256SUMS.
On success it writes full_pool_READY, the marker the w9 notebooks look for before they
use the full pool, so the folder can serve as their data directory as it is.
usage (inside the downloaded folder): python join_full_pool.py [--keep-parts]
"""
import hashlib
import sys
from pathlib import Path
here = Path(__file__).resolve().parent
sums = dict(reversed(line.split(None, 1)) for line in
(here / "SHA256SUMS").read_text().splitlines() if line.strip())
target = here / "full_pool_fp16.npy"
parts = sorted(here.glob("full_pool_fp16.npy.part*"))
if not parts:
raise SystemExit("no full_pool_fp16.npy.part* files found")
h = hashlib.sha256()
with target.open("wb") as g:
for p in parts:
with p.open("rb") as f:
while b := f.read(64 << 20):
g.write(b); h.update(b)
print("joined", p.name, flush=True)
if h.hexdigest() != sums["full_pool_fp16.npy"]:
raise SystemExit("SHA-256 mismatch: the rebuilt file is not the original")
print("full_pool_fp16.npy rebuilt and verified")
(here / "full_pool_READY").write_text("join_full_pool.py " + sums["full_pool_fp16.npy"])
print("wrote full_pool_READY")
if "--keep-parts" not in sys.argv:
for p in parts:
p.unlink()