forked from beaker-project/beaker-project.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangelog.py
47 lines (40 loc) · 1.49 KB
/
changelog.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
import re
import datetime
BAD_VER_RELS = [
# divergent, so they don't produce a usable patch series
'0.8.0-24.1',
'0.8.1-5.1',
'0.8.1-5.2',
# pre-releases, not real releases that we want people to use
'0.8.99-1',
'0.8.99-2',
'0.8.99-3',
]
# Is there any better parser we could use here??? e.g. from rpm
class Release(object):
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
@property
def downloads(self):
if self.release != '-1':
return ['beaker-%s%s.patch' % (self.version, self.release)]
else:
return ['beaker-%s.tar.gz' % self.version,
'beaker-%s.tar.xz' % self.version]
def parse(spec):
_, _, changelog = spec.partition('\n%changelog\n')
releases = re.split(r'(?m)(^\*.*$)', changelog)
releases.pop(0) # empty string
while releases:
date, name, email, ver, rel = re.match(
r'\* \w{3} (\w{3} \d+ \d{4}) (.*?) <(.*?)> ([\d.]+)(-.*)?',
releases.pop(0)).groups()
changes = [c.replace('%%', '%') for c in re.split(r'(?m)^- ', releases.pop(0)) if c.split()]
if ver + rel in BAD_VER_RELS:
continue
date = datetime.datetime.strptime(date, '%b %d %Y').date()
yield Release(version=ver, release=rel, date=date, changes=changes,
name=name, email=email)
if (ver, rel) == ('0.6.2', '-1'):
break # don't bother with the really old stuff