Merge pull request #330634 from r-ryantm/auto-update/circumflex
[NixPkgs.git] / pkgs / servers / asterisk / update.py
blob1e50294169385e5e6eff5699334c8674b03580d8
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python3 -p python3 python3.pkgs.packaging python3.pkgs.beautifulsoup4 python3.pkgs.requests
3 # mirrored in ./default.nix
4 from packaging import version
5 from bs4 import BeautifulSoup
6 import re, requests, json
7 import os, sys
8 from pathlib import Path
10 URL = "https://downloads.asterisk.org/pub/telephony/asterisk/"
12 page = requests.get(URL)
13 changelog = re.compile("^ChangeLog-\d+\.\d+\.\d+\.md$")
14 changelogs = [a.get_text() for a in BeautifulSoup(page.text, 'html.parser').find_all('a') if changelog.match(a.get_text())]
15 major_versions = {}
16 for changelog in changelogs:
17 v = version.parse(changelog.removeprefix("ChangeLog-").removesuffix(".md"))
18 major_versions.setdefault(v.major, []).append(v)
20 out = {}
21 for mv in major_versions.keys():
22 v = max(major_versions[mv])
23 sha = requests.get(f"{URL}/asterisk-{v}.sha256").text.split()[0]
24 out["asterisk_" + str(mv)] = {
25 "version": str(v),
26 "sha256": sha
29 versions_path = Path(sys.argv[0]).parent / "versions.json"
31 try:
32 with open(versions_path, "r") as in_file:
33 in_data = json.loads(in_file.read())
34 for v in in_data.keys():
35 print(v + ":", in_data[v]["version"], "->", out[v]["version"])
36 except:
37 # nice to have for the PR, not a requirement
38 pass
40 with open(versions_path, "w") as out_file:
41 out_file.write(json.dumps(out, sort_keys=True, indent=2) + "\n")