-
Notifications
You must be signed in to change notification settings - Fork 3
/
make_index.py
61 lines (55 loc) · 1.38 KB
/
make_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
import hashlib
import os
import sys
import time
path = "gh-pages" if len(sys.argv) == 1 else sys.argv[1]
indexName = "index.html"
template = """<!DOCTYPE html>
<html>
<head><title>Package Index</title></head>
<body>
<h1>Package Index</h1>
<pre>
%LINKS%
</pre>
</body>
"""
link = '<a href="%s#sha256=%s" download="%s">%s</a>%s%s%11d'
def get_sha256(name):
sha256 = hashlib.sha256()
with open(os.path.join(path, name), "rb") as fptr:
while True:
data = fptr.read(1024 ** 2)
if not len(data):
break
sha256.update(data)
return sha256.hexdigest()
wheels = [
(name, name)
for name in os.listdir(path)
if name.endswith(".whl") or name.endswith(".tar.gz")
]
wheels = sorted(wheels)
maxnamelen = max(len(name) for name, url in wheels)
index = template.replace(
"%LINKS%",
"\n".join(
[
link
% (
url,
get_sha256(url),
name,
name,
" " * (maxnamelen + 3 - len(name)),
time.strftime(
"%Y-%m-%d %H:%M:%S",
time.gmtime(os.path.getmtime(os.path.join(path, name))),
),
os.path.getsize(os.path.join(path, name)),
)
for name, url in wheels
]
),
)
open(os.path.join(path, indexName), "w").write(index)