]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - debian/scripts/misc/git-ubuntu-log
UBUNTU: [Debian] git-ubuntu-log -- wrap long bug and commit titles
[mirror_ubuntu-zesty-kernel.git] / debian / scripts / misc / git-ubuntu-log
1 #!/usr/bin/python3
2
3 import os
4 import sys
5
6 import codecs
7 import urllib.request
8 import json
9
10 import textwrap
11
12 sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
13
14 # Suck up the git log output and extract the information we need.
15 bugs = []
16 entries = []
17 entry = None
18 subject_wait = False
19 for line in sys.stdin:
20 if line.startswith('commit '):
21 if entry and 'ignore' not in entry:
22 entries.append(entry)
23 entry = {}
24 subject_wait = True
25
26 elif line.startswith('Author: '):
27 bits = line.strip().split(maxsplit=1)
28 entry['author'] = bits[1]
29
30 elif subject_wait and line.startswith(' '):
31 subject_wait = False
32 entry['subject'] = line.strip()
33
34 elif line.startswith(' BugLink: ') and 'launchpad.net' in line:
35 bits = line.strip().split(maxsplit=1)
36 bits = bits[1].split('/')
37 entry.setdefault('bugs', []).append(bits[-1])
38
39 # Accumulate bug numbers.
40 if bits[-1] not in bugs:
41 bugs.append(bits[-1])
42
43 elif line.startswith(' Ignore:'):
44 entry['ignore'] = True
45
46
47 entries.reverse()
48
49 # Go through the entries and clear out authors for upstream commits.
50 for entry in entries:
51 if entry['subject'].startswith('UBUNTU:'):
52 entry['subject'] = entry['subject'][7:].strip()
53 else:
54 del entry['author']
55
56 # Lump everything without a bug at the bottom.
57 bugs.append('__packaging__')
58 bugs.append('__mainline__')
59
60 emit_nl = False
61 for bug in bugs:
62 if bug == '__packaging__':
63 title = 'Miscellaneous Ubuntu changes'
64 elif bug == '__mainline__':
65 title = 'Miscellaneous upstream changes'
66 else:
67 bug_info = None
68
69 try:
70 #urllib.request.urlcleanup()
71 request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
72 request.add_header('Cache-Control', 'max-age=0')
73 with urllib.request.urlopen(request) as response:
74 data = response.read()
75 bug_info = json.loads(data.decode('utf-8'))
76
77 title = bug_info['title']
78 if 'description' in bug_info:
79 for line in bug_info['description'].split('\n'):
80 if line.startswith('Kernel-Description:'):
81 title = line.split(' ', 1)[1]
82
83 except urllib.error.HTTPError:
84 title = 'INVALID or PRIVATE BUG'
85
86 title += ' (LP: #' + bug + ')'
87
88 emit_title = True
89 for entry in entries:
90 if (bug == '__packaging__' and 'bugs' not in entry and 'author' in entry) or \
91 (bug == '__mainline__' and 'bugs' not in entry and 'author' not in entry) or \
92 ('bugs' in entry and bug in entry['bugs']):
93 if emit_title:
94 if emit_nl:
95 print('')
96 emit_nl = True
97
98 title_lines = textwrap.wrap(title, 76)
99 print(' * ' + title_lines[0])
100 for line in title_lines[1:]:
101 print(' ' + line)
102
103 emit_title = False
104 title_lines = textwrap.wrap(entry['subject'], 76)
105 print(' - ' + title_lines[0])
106 for line in title_lines[1:]:
107 print(' ' + line)
108