-
Notifications
You must be signed in to change notification settings - Fork 3
/
make_index.py
executable file
·75 lines (66 loc) · 2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
import argparse
import hashlib
import os
import time
indexName = 'index.html'
template = """<!DOCTYPE html>
<html>
<head><title>large_image_wheels</title></head>
<body>
<h1>large_image_wheels</h1>
<pre>
%LINKS%
</pre>
</body>
"""
link = '<a href="%s%s#sha256=%s" download="%s">%s</a>%s%s%11d'
def get_sha256(path, 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()
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Create an index.html page for wheels')
parser.add_argument(
'path', help='The path where index.html will be created', nargs='?',
default='gh-pages')
parser.add_argument(
'-b', '--branch', '--wheel-branch',
help='A branch to reference if a prefix is used.',
default='wheelhouse')
parser.add_argument(
'-p', '--prefix',
help='A prefix to add to links. This defaults to None if path is '
'anything other than gh-pages. Otherwise, this defaults to '
'"https://github.com/girder/large_image_wheels/raw/".')
args = parser.parse_args()
path = args.path or 'gh-pages'
wpath = path
prefix = args.prefix or ''
if args.prefix is None and path == 'gh-pages':
prefix = 'https://github.com/girder/large_image_wheels/raw/'
if prefix and args.branch:
prefix = prefix.rstrip('/') + '/' + args.branch
if prefix:
prefix = prefix.rstrip('/') + '/'
wheels = [(name, name) for name in os.listdir(wpath) if name.endswith('whl')]
if not len(wheels) and args.branch:
wpath = args.branch
wheels = [(name, name) for name in os.listdir(wpath) if name.endswith('whl')]
wheels = sorted(wheels)
maxnamelen = max(len(name) for name, url in wheels)
index = template.replace('%LINKS%', '\n'.join([
link % (
prefix, url, get_sha256(wpath, url), name, name,
' ' * (maxnamelen + 3 - len(name)),
time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(os.path.getmtime(
os.path.join(wpath, name)))),
os.path.getsize(os.path.join(wpath, name)),
) for name, url in wheels]))
open(os.path.join(path, indexName), 'w').write(index)