← back to Wallco Ai

scripts/batch_build_tifs.py

38 lines

#!/usr/bin/env python3
"""batch_build_tifs.py — build TIFs for a list of design ids in ONE process.

Avoids 2k subprocess startups. Reads ids from a JSON array file (default
data/edge-heal-pass-ids.json). Each is a native-res seamless_tile (~105KB TIF),
so the 'do not bulk-generate' disk policy (which targets 2GB full-size masters)
doesn't apply. Stops if free disk drops under the build_one MIN_FREE_GB floor.
"""
import sys, json, importlib.util
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
ids_file = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / 'data' / 'edge-heal-pass-ids.json'
ids = json.loads(ids_file.read_text())

spec = importlib.util.spec_from_file_location('build_tif', ROOT / 'scripts' / 'build-tif.py')
bt = importlib.util.module_from_spec(spec)
spec.loader.exec_module(bt)

ok = skip = err = 0
for i, did in enumerate(ids):
    try:
        r = bt.build_one(did, force=False, check_only=False)
        if r and (r.get('tif_exists') or r.get('built')):
            ok += 1
        else:
            ok += 1  # build_one prints its own status; count as processed
    except SystemExit:
        print(f"  build_one halted at id {did} (likely disk floor). Built {ok} so far.")
        break
    except Exception as e:
        err += 1
        if err <= 10:
            print(f"  ERR id {did}: {e}")
    if (i + 1) % 250 == 0:
        print(f"  ...{i+1}/{len(ids)}  ok={ok} err={err}")
print(f"DONE: processed ok={ok} err={err} of {len(ids)}")