-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnews2changelog.py
More file actions
42 lines (38 loc) · 1.6 KB
/
Copy pathnews2changelog.py
File metadata and controls
42 lines (38 loc) · 1.6 KB
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
from datetime import date
from re import compile as recompile
regex=recompile(r'^Version (?P<major>[.0-9]+)[.](?P<minor>[.0-9]+) '
r'\(released (?P<year>[0-9]+)-(?P<month>[0-9]+)-(?P<day>[0-9]+)\)$')
def iter_changes(lines):
version=None
changes={}
for line in filter(None,lines):
match=regex.match(line)
if match:
version=int(match['major']),int(match['minor'])
year,month,day=int(match['year']),int(match['month']),int(match['day'])
changes[version]={'date':date.fromisoformat(f'{year:04}-{month:02}-{day:02}'),
'logs':[]}
elif version:
changes[version]['logs'].append(f' {line}')
for version in reversed(sorted(changes.keys())):
yield version,changes[version]['date'],changes[version]['logs']
if __name__=='__main__':
with open('cryptodev-linux/NEWS',mode='rt',encoding='utf8') as news,\
open('debian/changelog',mode='wt',encoding='utf8') as changelog:
for (major,minor),logdate,logs in iter_changes(map(str.rstrip,news)):
print(f'cryptodev-linux ({major}.{minor}-1) unstable; urgency=low',
file=changelog)
print(file=changelog)
for line in logs:
print(line,file=changelog)
print(file=changelog)
print(' -- Maintaincer <user@email.address> ',
f'{logdate:%a, %d %b %Y %T +0000}',
file=changelog)
print(file=changelog)
# Local Variables:
# coding: utf-8
# mode: python
# python-indent-offset: 4
# indent-tabs-mode: nil
# End: