-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate-releases-index.py
executable file
·157 lines (140 loc) · 5.74 KB
/
generate-releases-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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/python -B
# vim: set fileencoding=utf8 :
"""
Writes out the Releases page (or feed) to stdout, based on tags in Beaker's git.
"""
import git_tags
# Keep this, otherwise genshi will result with an UndefinedError
from itertools import groupby, takewhile
import sys
from genshi.template import MarkupTemplate
import codecs
# The encoding for stdout can be None if stdout is redirected into a file, but
# set to the preferred terminal encoding if printed to a terminal. If it's
# None, the script may result in a Traceback if it tries to encode unicode
# instances with non-ASCII characters.
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
_checksums = dict(reversed(line.rstrip('\n').split()) for line in open('releases/SHA256SUM'))
def checksum(filename):
return _checksums[filename]
html_template = MarkupTemplate(u'''
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/">
<head>
<title>Beaker releases</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="../style.css" rel="stylesheet" type="text/css"/>
<link href="../releases.css" rel="stylesheet" type="text/css"/>
<link rel="profile" href="http://microformats.org/profile/hatom" />
<link rel="alternate" type="application/atom+xml" title="Atom feed" href="index.atom" />
</head>
<body>
<div class="header">
<div class="body_element">
<div class="title">
<a href="../"><img src="../images/logo.png" alt="Beaker" width="110" height="40" /></a>
</div>
<nav class="menu">
<form class="search" method="get" action="../search.html">
<input type="search" name="q" placeholder="search" />
</form>
<a href="../docs/">docs</a>
<a href="../dev/">develop</a>
<a href="../download.html">download</a>
</nav>
</div>
</div>
<div class="main_content">
<div class="body_element">
<h1>Releases</h1>
<p>You can verify the integrity of the tarballs by comparing the SHA256 hash
against the value shown on this page. Git tags for Beaker releases are also
<a href="../gpg/">signed with a committer’s GPG key</a>.</p>
<section py:for="major, releases in groupby(releases, lambda r: r.major)">
<h2>Beaker ${major}</h2>
<article class="release hentry" py:for="release in releases" id="beaker-${release.version}-1">
<h2 class="entry-title">Beaker ${release.version}</h2>
<div class="date">
<time datetime="${release.timestamp}" pubdate="pubdate">${release.timestamp.strftime('%-1d %B %Y')}</time>
</div>
<div class="relnotes-link">
<a href="${release.relnotes_href}">Release notes</a>
</div>
<div class="changelog-link">
<a href="${release.changelog_href}">Change log</a>
</div>
<div class="author vcard">
<span class="fn" title="${release.name}" />
<a class="email" href="mailto:${release.email}" />
</div>
<div class="downloads entry-content">
<p py:for="download in release.downloads"
class="download ${'.tar' in download and 'tarball' or ''} ${'.patch' in download and 'patch' or ''}">
<a href="${download}">${download}</a><br />
<span class="hash">SHA256: <tt>${checksum(download)}</tt></span>
</p>
</div>
</article>
</section>
<p>For older releases, please refer to
<a href="https://github.com/beaker-project/beaker">Beaker’s git repo</a>.</p>
</div>
</div>
</body>
</html>
''')
atom_template = MarkupTemplate(u'''
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:py="http://genshi.edgewall.org/"
xml:base="http://beaker-project.org/releases/index.atom">
<id>http://beaker-project.org/releases/index.atom</id>
<title type="text">Beaker releases</title>
<link rel="self" type="application/atom+xml" href="http://beaker-project.org/releases/index.atom" />
<link rel="alternate" href="http://beaker-project.org/releases/" />
<entry py:for="release in releases">
<id>http://beaker-project.org/releases/#beaker-${release.version}-1</id>
<link rel="alternate" href="http://beaker-project.org/releases/#beaker-${release.version}-1" />
<published>${release.timestamp.isoformat('T')}</published>
<author>
<name>${release.name}</name>
<email>${release.email}</email>
</author>
<title type="text">Beaker ${release.version}</title>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p><a href="${release.relnotes_href}">Release notes</a></p>
<p><a href="${release.changelog_href}">Change log</a></p>
<p py:for="download in release.downloads">
<a href="${download}">${download}</a><br />
<span class="hash">SHA256: <tt>${checksum(download)}</tt></span>
</p>
</div>
</content>
</entry>
</feed>
''')
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser('usage: %prog [options] GIT_DIR', description=__doc__)
parser.add_option('-f', '--format', type='choice', choices=['html', 'atom'],
help='Output format [default: %default]')
parser.set_defaults(format='html')
options, args = parser.parse_args()
if len(args) != 1:
parser.error('Specify Beaker git dir')
releases = git_tags.releases(args[0])
if options.format == 'html':
stream = html_template.generate(**globals())
# Set encoding to None to default to a unicode instance. Otherwise
# stdout will try to re-encode the utf-8 string resulting in a
# UnicodeEncodeError
sys.stdout.write(stream.render('xhtml', doctype='html5', encoding=None))
elif options.format == 'atom':
stream = atom_template.generate(**globals())
sys.stdout.write(stream.render('xml'))
else:
assert False