9 from bs4
import BeautifulSoup
11 parser
= argparse
.ArgumentParser(
12 description
="Get all available versions listed for a package in a site."
17 default
=os
.environ
.get("UPDATE_NIX_PNAME"),
18 required
="UPDATE_NIX_PNAME" not in os
.environ
,
19 help="name of the package",
23 default
=os
.environ
.get("UPDATE_NIX_ATTR_PATH"),
24 help="attribute path of the package",
26 parser
.add_argument("--url", help="url of the page that lists the package versions")
27 parser
.add_argument("--file", help="file name for writing debugging information")
29 parser
.add_argument("--extra-regex", help="additional regex to filter versions with")
32 if __name__
== "__main__":
33 args
= parser
.parse_args()
37 attr_path
= args
.attr_path
or pname
39 url
= args
.url
or json
.loads(
40 subprocess
.check_output(
46 f
"with import ./. {{}}; dirOf (lib.head {attr_path}.src.urls)",
52 # print a debugging message
54 with
open(args
.file, "a") as f
:
55 f
.write(f
"# Listing versions for {pname} from {url}\n")
57 page
= requests
.get(url
)
58 soup
= BeautifulSoup(page
.content
, "html.parser")
59 links
= soup
.find_all("a")
61 link_url
= link
.get("href", None)
62 if link_url
is not None:
64 rf
"(.*/)?{args.pname}-([\d.]+?(-[\d\w.-]+?)?)(\.tar)?(\.[^.]*)", link_url
67 version
= match
.group(2)
68 if (not args
.extra_regex
) or re
.fullmatch(args
.extra_regex
, version
):