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