-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_md.py
87 lines (70 loc) · 3.13 KB
/
to_md.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
76
77
78
79
80
81
82
83
84
85
86
87
import functools
import itertools
import operator
import re
import sys
from urllib.parse import quote_plus
import natsort
import humanize
from packaging.utils import parse_wheel_filename
PREFIX='https://s3.amazonaws.com/ifcopenshell-builds/'
def _():
import json
d = json.load(open(sys.argv[1]))
for c in d['Contents']:
k = c['Key']
if k.endswith('.zip'):
parts = k[:-4].rsplit('-', 3)
if len(parts) == 4:
product, version, hash, os = parts
if product in {'IfcConvert', 'IfcGeomServer'}:
pass
elif re.match(r'^ifcopenshell-python-\d{2,3}u?$', product):
pass
else:
continue
if len(hash) == 7:
pass
else:
continue
if re.match(r'^v\d\.\d\.\d+$', version):
pass
else:
continue
if os in {'macosm164', 'macos64', 'linux64', 'linuxarm64', 'win32', 'win64', 'linux32'}:
pass
else:
continue
yield version, hash, c['LastModified'], product, os, c['Size'], k
elif k.endswith('.whl'):
fixed = k.replace('ifcopenshell-python', 'ifcopenshell_python')
fixed = re.sub(r'(v\d\.\d\.\d)(\-|\+)(\w{7})', 'v0.8.1+\\3', fixed)
try:
module_name, version, _, tags = parse_wheel_filename(fixed)
except:
continue
if module_name == "ifcopenshell":
module_name += "-python"
if len(tags) != 1:
continue
tag = next(iter(tags))
if 'wasm' not in tag.platform:
continue
abi = re.sub('c|p|y', '', tag.abi)
yield f'v{version.public}', version.local, c['LastModified'], f'{module_name}-{abi}', 'WASM', c['Size'], k
hashtodate = dict((hash, functools.reduce(min, (t[1] for t in hash_dates))) for hash, hash_dates in itertools.groupby(sorted((a[1],a[2]) for a in _()), key=operator.itemgetter(0)))
data = natsort.natsorted(_(), reverse=True)
for section, subsections in itertools.groupby(data, key=operator.itemgetter(0)):
print('##', section)
for hash, rows in itertools.groupby(sorted(subsections, key=lambda t: hashtodate[t[1]], reverse=True), key=operator.itemgetter(1)):
print('###', hash, '(%s)' % hashtodate[hash])
rows = list(rows)
product, os, size = map(lambda vs: natsort.natsorted(set(vs)), zip(*(r[3:6] for r in rows)))
osh = list(map(lambda s: s[0].upper() + s[1:], map(lambda s: re.sub(r'(32|64)', ' \\1bit', s.replace('m1', ' M1').replace('arm', ' ARM')).replace('os', 'OS'), os)))
d = dict((r[3:5], (humanize.naturalsize(r[5]), quote_plus(r[6]))) for r in rows)
print()
print('item|', '|'.join(osh))
print('|'.join(['---']*(len(osh) + 1)))
for p in product:
print(p, '|', '|'.join(map(lambda t: '[%%s](%s%%s)' % PREFIX % t, (d.get((p, o), ('-', '')) for o in os))))
print()