libuv-svace-build
122 строки · 2.6 Кб
1#!/usr/bin/python3
2
3import itertools4import os5import re6import subprocess7
8HTML = r'''9<!DOCTYPE html>
10<html>
11<head>
12<link rel="stylesheet" href="http://libuv.org/styles/vendor.css">
13<link rel="stylesheet" href="http://libuv.org/styles/main.css">
14<style>
15table {{
16border-spacing: 0;
17}}
18body table {{
19margin: 0 0 0 12pt;
20}}
21th, td {{
22padding: 2pt;
23text-align: left;
24vertical-align: top;
25}}
26table table {{
27border-collapse: initial;
28padding: 0 0 16pt 0;
29}}
30table table tr:nth-child(even) {{
31background-color: #777;
32}}
33</style>
34</head>
35<body>
36<table>{groups}</table>
37</body>
38</html>
39'''
40
41GROUPS = r'''42<tr>
43<td>{groups[0]}</td>
44<td>{groups[1]}</td>
45<td>{groups[2]}</td>
46<td>{groups[3]}</td>
47</tr>
48'''
49
50GROUP = r'''51<table>
52<tr>
53<th>version</th>
54<th>tarball</th>
55<th>gpg</th>
56<th>windows</th>
57</tr>
58{rows}
59</table>
60'''
61
62ROW = r'''63<tr>
64<td>
65<a href="http://dist.libuv.org/dist/{tag}/">{tag}</a>
66</td>
67<td>
68<a href="http://dist.libuv.org/dist/{tag}/libuv-{tag}.tar.gz">tarball</a>
69</td>
70<td>{maybe_gpg}</td>
71<td>{maybe_exe}</td>
72</tr>
73'''
74
75GPG = r'''76<a href="http://dist.libuv.org/dist/{tag}/libuv-{tag}.tar.gz.sign">gpg</a>
77'''
78
79# The binaries don't have a predictable name, link to the directory instead.
80EXE = r'''81<a href="http://dist.libuv.org/dist/{tag}/">exe</a>
82'''
83
84def version(tag):85return list(map(int, re.match('^v(\d+)\.(\d+)\.(\d+)', tag).groups()))86
87def major_minor(tag):88return version(tag)[:2]89
90def row_for(tag):91maybe_gpg = ''92maybe_exe = ''93# We didn't start signing releases and producing Windows installers94# until v1.7.0.95if version(tag) >= version('v1.7.0'):96maybe_gpg = GPG.format(**locals())97maybe_exe = EXE.format(**locals())98return ROW.format(**locals())99
100def group_for(tags):101rows = ''.join(row_for(tag) for tag in tags)102return GROUP.format(rows=rows)103
104# Partition in groups of |n|.
105def groups_for(groups, n=4):106html = ''107groups = groups[:] + [''] * (n - 1)108while len(groups) >= n:109html += GROUPS.format(groups=groups)110groups = groups[n:]111return html112
113if __name__ == '__main__':114os.chdir(os.path.dirname(__file__))115tags = subprocess.check_output(['git', 'tag'], text=True)116tags = [tag for tag in tags.split('\n') if tag.startswith('v')]117tags.sort(key=version, reverse=True)118groups = [group_for(list(g)) for _, g in itertools.groupby(tags, major_minor)]119groups = groups_for(groups)120html = HTML.format(groups=groups).strip()121html = re.sub('>\\s+<', '><', html)122print(html)123