-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgbp-prepare.py
executable file
·47 lines (35 loc) · 1.26 KB
/
gbp-prepare.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
#!/usr/bin/python3
import email.parser
import subprocess
def fixup(name, content):
mail = email.parser.Parser().parsestr(content)
if 'Description' in mail and 'Subject' not in mail:
mail['Subject'] = mail['Description']
del mail['Description']
if 'Author' in mail and 'From' not in mail:
mail['From'] = mail['Author']
del mail['Author']
if 'Date' not in mail:
lines = subprocess.check_output(['git', 'log', '--format=%aD', name]).strip().split(b'\n')
first_authored = next(reversed(lines)).decode('utf-8')
mail['Date'] = first_authored
errors = set(mail.keys()) - {'Subject', 'From', 'Date'}
prefix = ''
for key in errors:
prefix += '{}: {}\n'.format(key, mail[key])
del mail[key]
mail.set_payload(prefix + mail.get_payload())
return str(mail)
def main():
with open('debian/patches/series') as s:
for line in s:
line = line.strip()
if not line or line.startswith('#'):
continue
name = 'debian/patches/{}'.format(line)
with open(name) as f:
new = fixup(name, f.read())
with open(name, 'w') as f:
f.write(new)
if '__main__' == __name__:
main()