make_dist_html.py 2.6 KB

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