traefik: add djds as maintainer (#377217)
[NixPkgs.git] / pkgs / by-name / pi / picoscope / update.py
blobecbd2292030d4e0e575c89e5c40b757603415dd0
1 #!/usr/bin/env nix-shell
2 #!nix-shell --pure -i python3 -p "python3.withPackages (ps: with ps; [ requests ])"
3 import json
4 import os
5 import requests
6 import sys
8 def parse_packages(text):
9 res = []
10 for package in resp.text.split("\n\n"):
11 if not package: continue
12 pkg = {}
13 for field in package.split("\n"):
14 if field.startswith(" "): # multiline string
15 pkg[k] += "\n" + field[1:]
16 else:
17 [k, v] = field.split(": ", 1)
18 pkg[k] = v
19 res.append(pkg)
20 return res
22 def generate_sources(packages):
23 sources_spec = {}
24 for pkg in pkgs:
25 sources_spec[pkg['Package']] = {
26 "url": "https://labs.picotech.com/rc/picoscope7/debian/" + pkg["Filename"],
27 "sha256": pkg["SHA256"],
28 "version": pkg["Version"]
30 return sources_spec
32 out = {}
33 for nix_system, release in {"x86_64-linux": "amd64"}.items():
34 resp = requests.get("https://labs.picotech.com/rc/picoscope7/debian//dists/picoscope/main/binary-"+release+"/Packages")
35 if resp.status_code != 200:
36 print("error: could not fetch data for release {} (code {})".format(release, resp.code), file=sys.stderr)
37 sys.exit(1)
38 pkgs = parse_packages(resp.text)
39 out[nix_system] = generate_sources(pkgs)
41 with open(os.path.dirname(__file__) + "/sources.json", "w") as f:
42 json.dump(out, f, indent=2, sort_keys=True)
43 f.write('\n')