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
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())]
16 for changelog
in changelogs
:
17 v
= version
.parse(changelog
.removeprefix("ChangeLog-").removesuffix(".md"))
18 major_versions
.setdefault(v
.major
, []).append(v
)
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
)] = {
29 versions_path
= Path(sys
.argv
[0]).parent
/ "versions.json"
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"])
37 # nice to have for the PR, not a requirement
40 with
open(versions_path
, "w") as out_file
:
41 out_file
.write(json
.dumps(out
, sort_keys
=True, indent
=2) + "\n")