File size: 1,314 Bytes
fbcfd46
 
9984d35
 
 
fbcfd46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9984d35
 
fbcfd46
 
 
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
"""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()