Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#! /usr/bin/env nix-shell
2#! nix-shell -i python3 --packages 'python3.withPackages (ps: with ps; [ requests beautifulsoup4 ])'
3import os
4import re
5import json
6import requests
7from bs4 import BeautifulSoup
8
9SITE = "https://download.racket-lang.org"
10MANIFEST_FILENAME = "manifest.json"
11
12def find_info(table, group_name, subgroup_name):
13 group = table.find(
14 string=re.compile("^{}\\s*".format(group_name))
15 ).find_parent("tr", class_="group")
16 subgroup = group.find_next(
17 string=re.compile("^{}\\s*".format(subgroup_name))
18 ).find_parent(class_="subgroup")
19 link = subgroup.find_next(
20 "a",
21 class_="installer",
22 string="Source"
23 )
24 filename = link["href"].split("/")[1]
25 sha256 = link.find_next(class_="checksum").string
26
27 return {
28 "filename": filename,
29 "sha256": sha256,
30 }
31
32os.chdir(os.path.dirname(os.path.abspath(__file__)))
33
34prev_version = os.environ["UPDATE_NIX_OLD_VERSION"]
35
36homepage = BeautifulSoup(requests.get(SITE).text, "html.parser")
37
38version = homepage.find(
39 "h3",
40 string=re.compile("^Version \\d+\\.\\d+")
41).string.split()[1]
42if version == prev_version:
43 raise Exception("no newer version available")
44
45down_page_path = homepage.find(
46 "a",
47 string="More Installers and Checksums"
48)["href"]
49down_page = BeautifulSoup(requests.get(SITE + "/" + down_page_path).text, "html.parser")
50down_table = down_page.find(class_="download-table")
51
52full = find_info(down_table, "Racket", "Unix")
53minimal = find_info(down_table, "Minimal Racket", "All Platforms")
54
55with open(MANIFEST_FILENAME, "w", encoding="utf-8") as f:
56 json.dump({
57 "version": version,
58 "full": full,
59 "minimal": minimal,
60 }, f, indent=2, ensure_ascii=False)
61 f.write("\n")
62
63print(json.dumps(
64 [
65 {
66 "attrPath": os.environ["UPDATE_NIX_ATTR_PATH"],
67 "oldVersion": prev_version,
68 "newVersion": version,
69 "files": [ os.path.abspath(MANIFEST_FILENAME) ],
70 },
71 ],
72 indent=2, ensure_ascii=False
73))