-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_updates.py
50 lines (36 loc) · 1.25 KB
/
gen_updates.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
import json
import os
import re
VERSION_RE = re.compile(r"""comfortable_panda-(\d+)\.(\d+)\.(\d+)(?:-fx)?.xpi""")
def gen_version(xpi_name) -> dict:
m = VERSION_RE.match(xpi_name)
if not m:
raise ValueError(f"Invalid xpi name: {xpi_name}")
version = f"{m.group(1)}.{m.group(2)}.{m.group(3)}"
v1 = int(m.group(1))
v2 = int(m.group(2))
v3 = int(m.group(3))
vs = (v1, v2, v3)
if vs <= (3, 0, 0):
update_link = f"https://das82.com/downloads/comfortable_panda-{version}-fx.xpi"
elif vs <= (5, 0, 0):
update_link = f"https://tinaxd.github.io/comfortable-panda-firefox-updates/comfortable_panda-{version}-fx.xpi"
else:
update_link = f"https://tinaxd.github.io/comfortable-panda-firefox-updates/comfortable_panda-{version}.xpi"
return {"version": version, "update_link": update_link}
def main() -> None:
files = os.listdir(".")
xpis = []
for file in files:
if file.endswith(".xpi"):
xpis.append(file)
xpis.sort()
j = {
"addons": {
"comfortable.panda@das08": {"updates": [gen_version(xpi) for xpi in xpis]}
}
}
with open("updates.json", "w") as f:
json.dump(j, f, indent=2)
if __name__ == "__main__":
main()