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