This repository has been archived by the owner on Jan 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathupdate_index.py
65 lines (48 loc) · 1.78 KB
/
update_index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
import json
import argparse
import subprocess
HEADER = """
<!-- Generated by jax-windows-builder/update_index.py, do not update manually! -->
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
""".strip("\n")
FOOTER = "</body>\n</html>\n"
ABSOLUTE_URL_PATTERN = "https://whls.blob.core.windows.net/{container}/{key}"
RELATIVE_URL_PATTERN = "./{key}"
if not os.environ.get("AZURE_STORAGE_CONNECTION_STRING"):
sys.stderr.write("Environment variable AZURE_STORAGE_CONNECTION_STRING is not properly set.\n")
sys.stderr.write("Abort!\n")
exit(-1)
parser = argparse.ArgumentParser(description="Generates and/or update package indexes html file for pip.")
parser.add_argument("container", choices=["unstable", "releases"])
parser.add_argument("--url_mode", default="relative", choices=["absolute", "relative"])
args = parser.parse_args()
def entry(key):
if args.url_mode == "relative":
url_pattern = RELATIVE_URL_PATTERN
else:
url_pattern = ABSOLUTE_URL_PATTERN
link_href = url_pattern.format(key=key, container=args.container)
link_title = link_href
return f'<a href="{link_href}">{key}</a><br>'
def get_entries():
entries = []
proc_args = ["az.cmd", "storage", "blob", "list", "--output=json", f"--container-name={args.container}"]
sys.stderr.write(f"Running command: {' '.join(proc_args)}\n")
json_str = subprocess.check_output(proc_args)
j = json.loads(json_str)
for item in j:
key = item["name"]
if key.endswith(".whl"):
entries.append(entry(key))
return entries
def gen_index_html(entries):
html = [HEADER]
html.extend(entries)
html.append(FOOTER)
return "\n".join(html)
html = gen_index_html(get_entries())
print(html)