Merge lp:~vorlon/apport/ubuntu-bugpatterns-python3 into lp:~ubuntu-bugcontrol/apport/ubuntu-bugpatterns

Proposed by Steve Langasek
Status: Needs review
Proposed branch: lp:~vorlon/apport/ubuntu-bugpatterns-python3
Merge into: lp:~ubuntu-bugcontrol/apport/ubuntu-bugpatterns
Diff against target: 305 lines (+42/-42)
7 files modified
bugpattern_written.py (+4/-4)
check-patterns-for-fixed-bugs (+4/-4)
consolidate-bugs (+10/-10)
convert.py (+1/-1)
search-bugs (+6/-6)
test-local (+11/-11)
update-tags (+6/-6)
To merge this branch: bzr merge lp:~vorlon/apport/ubuntu-bugpatterns-python3
Reviewer Review Type Date Requested Status
Brian Murray Pending
Review via email: mp+367798@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

590. By Steve Langasek

python3 like it's 1999

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bugpattern_written.py'
2--- bugpattern_written.py 2011-12-05 22:45:24 +0000
3+++ bugpattern_written.py 2019-05-22 19:06:21 +0000
4@@ -1,4 +1,4 @@
5-#!/usr/bin/python
6+#!/usr/bin/python3
7 # Author: Brian Murray <brian@canonical.com>
8 # Copyright (C) 2011 Canonical, Ltd.
9 # License: GPLv3
10@@ -43,15 +43,15 @@
11 for bug_number in bug_numbers:
12 bug = lp.get_bug(bug_number)
13 if bug.private:
14- print 'LP: #%s is private and should be made public' % bug_number
15+ print('LP: #%s is private and should be made public' % bug_number)
16 if not 'bugpattern-needed' in bug.tags:
17 bug.tags.append('bugpattern-written')
18- print 'LP: #%s didn\'t need a bug pattern' % bug_number
19+ print('LP: #%s didn\'t need a bug pattern' % bug_number)
20 continue
21 bug.tags.remove('bugpattern-needed')
22 bug.tags.append('bugpattern-written')
23 bug.lpbug.unsubscribe(person=bugcontrol)
24- print 'LP: #%s modified by bug pattern written bzr hook' % bug_number
25+ print('LP: #%s modified by bug pattern written bzr hook' % bug_number)
26
27 branch.Branch.hooks.install_named_hook('post_push', post_push_hook,
28 'Bug pattern written hook')
29
30=== modified file 'check-patterns-for-fixed-bugs'
31--- check-patterns-for-fixed-bugs 2012-06-28 21:33:21 +0000
32+++ check-patterns-for-fixed-bugs 2019-05-22 19:06:21 +0000
33@@ -1,4 +1,4 @@
34-#!/usr/bin/python
35+#!/usr/bin/python3
36 #
37 # Author: Brian Murray <brian@canonical.com>
38 # Copyright (C) 2012 Canonical, Ltd.
39@@ -27,7 +27,7 @@
40 def connect():
41 cachedir = os.path.expanduser('~/.launchpadlib/cache')
42 if not os.path.exists(cachedir):
43- os.makedirs(cachedir,0700)
44+ os.makedirs(cachedir,0o700)
45 root = 'production'
46 credfile = os.path.expanduser('~/.cache/apport/launchpad.credentials')
47 launchpad = Launchpad.login_with(sys.argv[0], credentials_file=credfile,
48@@ -65,7 +65,7 @@
49 bug_numbers = []
50
51 for pattern in dom.getElementsByTagName('pattern'):
52- if not pattern.attributes.has_key('url'):
53+ if 'url' not in pattern.attributes:
54 continue
55
56 url = pattern.attributes['url'].nodeValue
57@@ -75,7 +75,7 @@
58 for cn in pattern.childNodes:
59 # regular expression condition
60 if cn.nodeType == xml.dom.Node.ELEMENT_NODE and cn.nodeName == 're' and \
61- cn.attributes.has_key('key'):
62+ 'key' in cn.attributes:
63 key = cn.attributes['key'].nodeValue
64 if key == 'SourcePackage':
65 value = cn.childNodes[0].nodeValue
66
67=== modified file 'consolidate-bugs'
68--- consolidate-bugs 2011-12-08 21:45:43 +0000
69+++ consolidate-bugs 2019-05-22 19:06:21 +0000
70@@ -1,4 +1,4 @@
71-#!/usr/bin/python
72+#!/usr/bin/python3
73 #
74 # Author: Brian Murray <brian@canonical.com>
75 # Copyright (C) 2011 Canonical, Ltd.
76@@ -29,12 +29,12 @@
77 packages = []
78
79 for pattern in dom.getElementsByTagName('pattern'):
80- if not pattern.attributes.has_key('url'):
81+ if 'url' not in pattern.attributes:
82 continue
83
84 for cn in pattern.childNodes:
85 if cn.nodeType == xml.dom.Node.ELEMENT_NODE and cn.nodeName == 're' \
86- and cn.attributes.has_key('key'):
87+ and 'key' in cn.attributes:
88 key = cn.attributes['key'].nodeValue
89 if key == 'PackageVersion':
90 continue
91@@ -42,21 +42,21 @@
92 continue
93 if cn.hasChildNodes() and \
94 cn.childNodes[0].nodeType == xml.dom.Node.TEXT_NODE:
95- package = cn.childNodes[0].nodeValue.encode('UTF-8')
96+ package = cn.childNodes[0].nodeValue
97 package = package.replace('^', '')
98 package = package.strip()
99 if package not in packages:
100 packages.append(package)
101
102 for package in packages:
103- print 'search-bugs --package %s --tags apport-crash --within 2 -C' % \
104- package
105+ print('search-bugs --package %s --tags apport-crash --within 2 -C' % \
106+ package)
107 results = Popen(['./search-bugs','--package', '%s' % package, '--tags',
108 'apport-crash', '--within', '2', '-C'], stdout=PIPE).communicate()[0]
109- print results
110+ print(results)
111 # need to do apport-bug bugs too
112- print 'search-bugs --package %s --tags apport-bug --within 2 -C' % \
113- package
114+ print('search-bugs --package %s --tags apport-bug --within 2 -C' % \
115+ package)
116 results = Popen(['./search-bugs','--package', '%s' % package, '--tags',
117 'apport-bug', '--within', '2', '-C'], stdout=PIPE).communicate()[0]
118- print results
119+ print(results)
120
121=== modified file 'convert.py'
122--- convert.py 2011-02-24 20:40:52 +0000
123+++ convert.py 2019-05-22 19:06:21 +0000
124@@ -1,4 +1,4 @@
125-#!/usr/bin/python
126+#!/usr/bin/python3
127
128 import glob
129 import os
130
131=== modified file 'search-bugs'
132--- search-bugs 2018-04-17 16:44:25 +0000
133+++ search-bugs 2019-05-22 19:06:21 +0000
134@@ -1,4 +1,4 @@
135-#!/usr/bin/python
136+#!/usr/bin/python3
137 # Author: Brian Murray <brian@canonical.com>
138 # Copyright (C) 2009 Canonical, Ltd.
139 # License: GPLv3
140@@ -22,7 +22,7 @@
141 def connect():
142 cachedir = os.path.expanduser('~/.launchpadlib/cache')
143 if not os.path.exists(cachedir):
144- os.makedirs(cachedir,0700)
145+ os.makedirs(cachedir,0o700)
146
147 root = 'production'
148 credfile = os.path.expanduser('~/.cache/apport/launchpad.credentials')
149@@ -114,7 +114,7 @@
150 'In Progress', 'Fix Committed' ]
151 elif opt.status:
152 if opt.status not in valid_status:
153- print >> sys.stderr, ("Invalid status '%s'. Aborting") % (opt.status)
154+ print("Invalid status '%s'. Aborting" % (opt.status), file=sys.stderr)
155 sys.exit(1)
156 else:
157 status_list.append(opt.status)
158@@ -127,7 +127,7 @@
159 print('Package %s not found in Ubuntu' % opt.package)
160 sys.exit(1)
161 elif not opt.package:
162- print >> sys.stderr, ("A package is required.")
163+ print("A package is required.", file=sys.stderr)
164 sys.exit(1)
165
166 if opt.dupes:
167@@ -178,7 +178,7 @@
168 trim_dpkg_log(report)
169
170 try:
171- match = report.search_bug_patterns('bugpatterns.xml')
172+ match = report.search_bug_patterns('file:///' + os.path.join(os.getcwd(), 'bugpatterns.xml'))
173 except AssertionError as error:
174 print("%s" % error)
175 continue
176@@ -188,7 +188,7 @@
177 master_number = match.split('/')[-1]
178 master = lp.bugs[master_number]
179 if str(master_number) == str(task_number) and not opt.all:
180- print "Reached master bug LP: #%s" % master_number
181+ print ("Reached master bug LP: #%s" % master_number)
182 break
183 if int(task_number) == int(master_number):
184 continue
185
186=== modified file 'test-local'
187--- test-local 2012-02-24 23:47:20 +0000
188+++ test-local 2019-05-22 19:06:21 +0000
189@@ -1,4 +1,4 @@
190-#!/usr/bin/python
191+#!/usr/bin/python3
192
193 import sys
194
195@@ -10,39 +10,39 @@
196 db = get_crashdb(None)
197 try:
198 report = db.download(bugnumber)
199- except IOError, e:
200+ except IOError as e:
201 if 'CRC check failed' in e.message:
202 print('Skipping %s because it has a bad attachment' % bugnumber)
203 return
204 match = report.search_bug_patterns('bugpatterns.xml')
205
206 if match:
207- print 'LP: #%s: Matched bug pattern: %s' % (bugnumber, match )
208+ print('LP: #%s: Matched bug pattern: %s' % (bugnumber, match ))
209 else:
210- print 'LP: #%s: No match' % bugnumber
211+ print('LP: #%s: No match' % bugnumber)
212
213 lp = Launchpad.login_with('apport', 'production')
214
215 if len(sys.argv) != 2:
216- print >> sys.stderr, 'Usage: %s <.crash file or bug number>' % sys.argv[0]
217+ print('Usage: %s <.crash file or bug number>' % sys.argv[0], file=sys.stderr)
218 sys.exit(1)
219
220 if not sys.argv[1].isdigit():
221 report = apport.Report()
222 try:
223 f = open(sys.argv[1])
224- except IOError, e:
225- print >> sys.stderr, 'Cannot open report file: %s' % str(e)
226+ except IOError as e:
227+ print('Cannot open report file: %s' % str(e), file=sys.stderr)
228 sys.exit(1)
229 report.load(f)
230 f.close()
231 match = report.search_bug_patterns('bugpatterns.xml')
232
233 if match:
234- print 'LP: #%s: Matched bug pattern: %s' % ( sys.argv[1], match )
235+ print('LP: #%s: Matched bug pattern: %s' % ( sys.argv[1], match ))
236 sys.exit(0)
237 else:
238- print 'LP: #%s: No match' % sys.argv[1]
239+ print('LP: #%s: No match' % sys.argv[1])
240 sys.exit(1)
241 else:
242 match_bug(sys.argv[1])
243@@ -51,10 +51,10 @@
244 # if bug is a duplicate - call this for parent
245 if bug.duplicate_of:
246 dupe = bug.duplicate_of.id
247- print 'LP: #%s is a duplicate of ....' % bug.id
248+ print('LP: #%s is a duplicate of ....' % bug.id)
249 match_bug(dupe)
250 if bug.duplicates:
251- print "Checking duplicate bugs..."
252+ print("Checking duplicate bugs...")
253 for duplicate in bug.duplicates:
254 # Skip if not an apport bug
255 if 'apport-crash' in duplicate.tags or \
256
257=== modified file 'update-tags'
258--- update-tags 2011-03-04 21:03:35 +0000
259+++ update-tags 2019-05-22 19:06:21 +0000
260@@ -1,4 +1,4 @@
261-#!/usr/bin/python
262+#!/usr/bin/python3
263 # Author: Matt Zimmerman <mdz@ubuntu.com>
264 # Copyright (C) 2011 Canonical, Ltd.
265 # License: GPLv3
266@@ -59,7 +59,7 @@
267 urls = set()
268
269 for pattern in dom.getElementsByTagName('pattern'):
270- if not pattern.attributes.has_key('url'): continue
271+ if 'url' not in pattern.attributes: continue
272
273 url = pattern.attributes['url'].nodeValue
274
275@@ -95,10 +95,10 @@
276
277 bugs_with_patterns = bug_numbers_from_urls(urls)
278 if not bugs_with_patterns:
279- print "No patterns found"
280+ print("No patterns found")
281 return
282
283- print "Found bug patterns for %d bugs" % len(bugs_with_patterns)
284+ print("Found bug patterns for %d bugs" % len(bugs_with_patterns))
285
286 db = BugDatabase()
287 db.connect(authenticated=not args.dry_run)
288@@ -114,7 +114,7 @@
289
290 if changes:
291 for bug, tag, state in changes:
292- print "%s - %s %s" % (bug_to_url(bug), state and 'add' or 'remove', tag)
293+ print("%s - %s %s" % (bug_to_url(bug), state and 'add' or 'remove', tag))
294 if args.dry_run: continue
295
296 if state:
297@@ -122,7 +122,7 @@
298 else:
299 db.bug_remove_tag(bug, tag)
300 else:
301- print "All good!"
302+ print("All good!")
303
304 if __name__ == '__main__':
305 main()