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