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
#!/usr/bin/env python3
import json
import sys
from pathlib import Path
def update(versions, record):
asset = record["asset"]
plat = record["platform"]
entry = versions.get("assets", {}).get(asset)
if entry is None:
raise SystemExit("update-pins: no asset %s" % asset)
tree = entry.get("platforms", {}).get(plat)
if tree is None:
raise SystemExit("update-pins: %s has no tree pin for %s" % (asset, plat))
tree["treeSha256"] = record["treeSha256"]
tree["rawBytes"] = record["rawBytes"]
tree["zstdBytes"] = record["zstdBytes"]
binary = record.get("binarySha256", "")
if binary:
fetch = entry.get("fetch", {}).get(plat)
if fetch is None or "sha256" not in fetch:
raise SystemExit("update-pins: %s has no binary pin for %s" % (asset, plat))
fetch["sha256"] = binary
def main():
if len(sys.argv) != 3:
raise SystemExit("usage: update-pins.py versions.json pins-dir")
path = Path(sys.argv[1])
pins = sorted(Path(sys.argv[2]).glob("*.json"))
old = path.read_text()
versions = json.loads(old)
if json.dumps(versions, indent=2) + "\n" != old:
raise SystemExit("update-pins: %s is not in json.dumps indent=2 form" % path)
for pin in pins:
update(versions, json.loads(pin.read_text()))
text = json.dumps(versions, indent=2) + "\n"
if text != old:
path.write_text(text)
print("stage-assets: updated pins in %s" % path, file=sys.stderr)
else:
print("stage-assets: pins unchanged in %s" % path, file=sys.stderr)
if __name__ == "__main__":
main()