-
Notifications
You must be signed in to change notification settings - Fork 3
/
lookup_packages_edgedb_com.py
83 lines (63 loc) · 2.21 KB
/
lookup_packages_edgedb_com.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Queries packages.edgedb.com and prints list of edgedb-server sources
# that can be copy pasted into the flake.nix.
#
# Run with:
#
# $ python lookup_packages_edgedb_com.py
#
import requests
from typing import Tuple, Any, Callable
platforms = [
{"nix": "x86_64-linux", "edgedb": "x86_64-unknown-linux-gnu"},
{"nix": "aarch64-linux", "edgedb": "aarch64-unknown-linux-gnu"},
{"nix": "x86_64-darwin", "edgedb": "x86_64-apple-darwin"},
{"nix": "aarch64-darwin", "edgedb": "aarch64-apple-darwin"},
]
basename = "edgedb-server"
channel = "" # stable
# channel = ".nightly"
def find_most_recent(packages) -> Tuple[int, int, int]:
major = 0
minor = 0
revision = 0
for p in packages:
if p["basename"] != basename:
continue
if p["version_details"]["major"] > major:
major = p["version_details"]["major"]
minor = 0
revision = 0
if p["version_details"]["minor"] > minor:
minor = p["version_details"]["minor"]
revision = 0
r = int(p["version_details"]["metadata"]["build_revision"])
if r > revision:
revision = r
return (major, minor, revision)
def package_selector(version) -> Callable[[Any], bool]:
def sel(p) -> bool:
return (
p["basename"] == basename
and p["version_details"]["major"] == version[0]
and p["version_details"]["minor"] == version[1]
and p["version_details"]["metadata"]["build_revision"] == str(version[2])
)
return sel
def install_ref_selector(i) -> bool:
return i["encoding"] == "zstd"
for platform in platforms:
res = requests.get(
f"https://packages.edgedb.com/archive/.jsonindexes/{platform['edgedb']}{channel}.json"
)
packages = res.json()["packages"]
version = find_most_recent(packages)
package = next(filter(package_selector(version), packages))
install_ref = next(filter(install_ref_selector, package["installrefs"]))
url = "https://packages.edgedb.com" + install_ref["ref"]
sha256 = install_ref["verification"]["sha256"]
print(
platform["nix"] + " = {\n"
f' url = "{url}";\n'
f' sha256 = "{sha256}";\n'
"};"
)