50 ap = argparse.ArgumentParser()
51 ap.add_argument(
"--records", required=
True, help=
"dir of new record JSON files")
52 ap.add_argument(
"--registry", required=
True, help=
"registry tree to merge into")
53 args = ap.parse_args()
55 records = sorted(Path(args.records).rglob(
"*.json"))
57 print(
"no records to merge", file=sys.stderr)
60 registry = Path(args.registry)
61 counts = {
"new": 0,
"updated": 0,
"unchanged": 0}
64 new = json.loads(path.read_text())
65 digest = new.get(
"image_digest")
66 board = new.get(
"board")
67 if not digest
or not board:
68 raise SystemExit(f
"{path}: record needs image_digest and board")
70 dest = registry / board / f
"{digest}.json"
71 existing = json.loads(dest.read_text())
if dest.is_file()
else None
74 if what !=
"unchanged":
75 dest.parent.mkdir(parents=
True, exist_ok=
True)
76 dest.write_text(json.dumps(merged, indent=2, sort_keys=
True) +
"\n")
77 print(f
"{what:9} {board}/{digest[:16]}…")
80 f
"\n{counts['new']} new, {counts['updated']} updated, "
81 f
"{counts['unchanged']} already current"