Merge ~cjwatson/launchpad:utilities-print-function into launchpad:master
- Git
- lp:~cjwatson/launchpad
- utilities-print-function
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | 1cfc64ebaf88e52476e51d300aa35446040480df |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:utilities-print-function |
Merge into: | launchpad:master |
Diff against target: |
1055 lines (+197/-146) 22 files modified
utilities/audit-security-settings.py (+4/-1) utilities/community-contributions.py (+7/-5) utilities/create-lp-wadl-and-apidoc.py (+11/-8) utilities/findimports.py (+23/-19) utilities/format-imports (+3/-1) utilities/get-branch-info (+12/-10) utilities/list-pages (+3/-1) utilities/lsconf.py (+10/-8) utilities/make-dummy-hosted-branches (+3/-1) utilities/make-lp-user (+12/-10) utilities/mock-code-import (+9/-7) utilities/paste (+5/-3) utilities/pgcreate.py (+3/-1) utilities/pgkillactive.py (+5/-3) utilities/pgkillidle.py (+5/-3) utilities/pglogwatch.py (+5/-3) utilities/pgmassacre.py (+15/-10) utilities/pgstats.py (+6/-4) utilities/report-database-stats.py (+40/-38) utilities/shhh.py (+4/-2) utilities/soyuz-sampledata-setup.py (+5/-3) utilities/update-copyright (+7/-5) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Colin Watson (community) | Approve | ||
Review via email: mp+380387@code.launchpad.net |
Commit message
Port utilities to print_function
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/utilities/audit-security-settings.py b/utilities/audit-security-settings.py |
2 | index 1095c3e..b41238d 100755 |
3 | --- a/utilities/audit-security-settings.py |
4 | +++ b/utilities/audit-security-settings.py |
5 | @@ -9,6 +9,9 @@ Usage hint: |
6 | |
7 | % utilities/audit-security.py |
8 | """ |
9 | + |
10 | +from __future__ import absolute_import, print_function |
11 | + |
12 | __metatype__ = type |
13 | |
14 | import _pythonpath |
15 | @@ -29,7 +32,7 @@ def main(): |
16 | auditor = SettingsAuditor(data) |
17 | settings = auditor.audit() |
18 | file(SECURITY_PATH, 'w').write(settings) |
19 | - print auditor.error_data |
20 | + print(auditor.error_data) |
21 | |
22 | if __name__ == '__main__': |
23 | main() |
24 | diff --git a/utilities/community-contributions.py b/utilities/community-contributions.py |
25 | index 8101fbe..26fe031 100755 |
26 | --- a/utilities/community-contributions.py |
27 | +++ b/utilities/community-contributions.py |
28 | @@ -39,6 +39,8 @@ Options: |
29 | # For understanding the code, you may find it helpful to see |
30 | # bzrlib/log.py and http://bazaar-vcs.org/Integrating_with_Bazaar. |
31 | |
32 | +from __future__ import absolute_import, print_function |
33 | + |
34 | import getopt |
35 | import re |
36 | import sys |
37 | @@ -621,7 +623,7 @@ log.log_formatter_registry.register('external_contributors', LogExCons, |
38 | |
39 | |
40 | def usage(): |
41 | - print __doc__ |
42 | + print(__doc__) |
43 | |
44 | |
45 | # Use backslashes to suppress newlines because this is wiki syntax, |
46 | @@ -700,7 +702,7 @@ def main(): |
47 | |
48 | logger = log.Logger(b, {'direction': 'reverse', 'levels': 0}) |
49 | if not quiet: |
50 | - print "Calculating (this may take a while)..." |
51 | + print("Calculating (this may take a while)...") |
52 | |
53 | # Set information about the current branch for later formatting. |
54 | lec.branch_info = branch_info |
55 | @@ -717,13 +719,13 @@ def main(): |
56 | |
57 | if not dry_run: |
58 | if not quiet: |
59 | - print "Updating wiki..." |
60 | + print("Updating wiki...") |
61 | # Not sure how to get editmoin to obey our quiet flag. |
62 | editshortcut(wiki_dest, editfile_func=update_if_modified) |
63 | if not quiet: |
64 | - print "Done updating wiki." |
65 | + print("Done updating wiki.") |
66 | else: |
67 | - print page_contents |
68 | + print(page_contents) |
69 | |
70 | |
71 | if __name__ == '__main__': |
72 | diff --git a/utilities/create-lp-wadl-and-apidoc.py b/utilities/create-lp-wadl-and-apidoc.py |
73 | index 3f26c72..fcfe9a0 100755 |
74 | --- a/utilities/create-lp-wadl-and-apidoc.py |
75 | +++ b/utilities/create-lp-wadl-and-apidoc.py |
76 | @@ -10,6 +10,9 @@ Example: |
77 | % LPCONFIG=development bin/py utilities/create-lp-wadl-and-apidoc.py \\ |
78 | "lib/canonical/launchpad/apidoc/wadl-development-%(version)s.xml" |
79 | """ |
80 | + |
81 | +from __future__ import absolute_import, print_function |
82 | + |
83 | import _pythonpath |
84 | |
85 | from multiprocessing import Process |
86 | @@ -63,12 +66,12 @@ def make_files(directory, version, timestamp, force): |
87 | (json_filename, json_index, generate_json, 'JSON')): |
88 | # If the src doesn't exist or we are forced to regenerate it... |
89 | if (not os.path.exists(src) or force): |
90 | - print "Writing %s for version %s to %s." % ( |
91 | - name, version, src) |
92 | + print("Writing %s for version %s to %s." % ( |
93 | + name, version, src)) |
94 | write(src, gen(version), timestamp) |
95 | else: |
96 | - print "Skipping already present %s file: %s" % ( |
97 | - name, src) |
98 | + print("Skipping already present %s file: %s" % ( |
99 | + name, src)) |
100 | # Make "index" symlinks, removing any preexisting ones. |
101 | if os.path.exists(dest): |
102 | os.remove(dest) |
103 | @@ -106,12 +109,12 @@ def make_files(directory, version, timestamp, force): |
104 | # If the HTML file doesn't exist or we're being forced to regenerate |
105 | # it... |
106 | if (not os.path.exists(html_filename) or force): |
107 | - print "Writing apidoc for version %s to %s" % ( |
108 | - version, html_filename) |
109 | + print("Writing apidoc for version %s to %s" % ( |
110 | + version, html_filename)) |
111 | write(html_filename, generate_html(wadl_filename, |
112 | suppress_stderr=False), timestamp) |
113 | else: |
114 | - print "Skipping already present HTML file:", html_filename |
115 | + print("Skipping already present HTML file:", html_filename) |
116 | |
117 | # Symlink the top-level version html in the version directory for |
118 | # completeness. |
119 | @@ -131,7 +134,7 @@ def main(directory, force=False): |
120 | template_file = 'apidoc-index.pt' |
121 | template = PageTemplateFile(template_file) |
122 | index_filename = os.path.join(directory, "index.html") |
123 | - print "Writing index:", index_filename |
124 | + print("Writing index:", index_filename) |
125 | f = open(index_filename, 'w') |
126 | f.write(template(config=config)) |
127 | |
128 | diff --git a/utilities/findimports.py b/utilities/findimports.py |
129 | index bd9e112..1ec49c0 100755 |
130 | --- a/utilities/findimports.py |
131 | +++ b/utilities/findimports.py |
132 | @@ -36,6 +36,8 @@ this program; if not, write to the Free Software Foundation, Inc., 675 Mass |
133 | Ave, Cambridge, MA 02139, USA. |
134 | """ |
135 | |
136 | +from __future__ import absolute_import, print_function |
137 | + |
138 | import compiler |
139 | from compiler import ast |
140 | from compiler.visitor import ASTVisitor |
141 | @@ -194,7 +196,8 @@ class ModuleGraph(object): |
142 | if filename.endswith(ext): |
143 | break |
144 | else: |
145 | - print >> sys.stderr, "%s: unknown file name extension" % filename |
146 | + print( |
147 | + "%s: unknown file name extension" % filename, file=sys.stderr) |
148 | longest_prefix_len = 0 |
149 | filename = os.path.abspath(filename) |
150 | for prefix in self.path: |
151 | @@ -221,8 +224,9 @@ class ModuleGraph(object): |
152 | return candidate |
153 | name = name[:name.rfind('.')] |
154 | if dotted_name not in self._warned_about: |
155 | - print >> sys.stderr, ("%s: could not find %s" |
156 | - % (filename, dotted_name)) |
157 | + print( |
158 | + "%s: could not find %s" % (filename, dotted_name), |
159 | + file=sys.stderr) |
160 | self._warned_about.add(dotted_name) |
161 | return dotted_name |
162 | |
163 | @@ -268,15 +272,15 @@ class ModuleGraph(object): |
164 | |
165 | def printImportedNames(self): |
166 | for module in self.listModules(): |
167 | - print "%s:" % module.modname |
168 | - print " %s" % "\n ".join(module.imported_names) |
169 | + print("%s:" % module.modname) |
170 | + print(" %s" % "\n ".join(module.imported_names)) |
171 | |
172 | def printImports(self): |
173 | for module in self.listModules(): |
174 | - print "%s:" % module.modname |
175 | + print("%s:" % module.modname) |
176 | imports = list(module.imports) |
177 | imports.sort() |
178 | - print " %s" % "\n ".join(imports) |
179 | + print(" %s" % "\n ".join(imports)) |
180 | |
181 | def printUnusedImports(self): |
182 | for module in self.listModules(): |
183 | @@ -289,31 +293,31 @@ class ModuleGraph(object): |
184 | if '#' in line: |
185 | continue # assume there's a comment explaining why it |
186 | # is not used |
187 | - print "%s:%s: %s not used" % (module.filename, lineno, name) |
188 | + print("%s:%s: %s not used" % (module.filename, lineno, name)) |
189 | |
190 | def printDot(self): |
191 | - print "digraph ModuleDependencies {" |
192 | - print " node[shape=box];" |
193 | + print("digraph ModuleDependencies {") |
194 | + print(" node[shape=box];") |
195 | allNames = set() |
196 | nameDict = {} |
197 | for n, module in enumerate(self.listModules()): |
198 | module._dot_name = "mod%d" % n |
199 | nameDict[module.modname] = module._dot_name |
200 | - print " %s[label=\"%s\"];" % (module._dot_name, module.modname) |
201 | + print(" %s[label=\"%s\"];" % (module._dot_name, module.modname)) |
202 | for name in module.imports: |
203 | if name not in self.modules: |
204 | allNames.add(name) |
205 | - print " node[style=dotted];" |
206 | + print(" node[style=dotted];") |
207 | names = list(allNames) |
208 | names.sort() |
209 | for n, name in enumerate(names): |
210 | nameDict[name] = id = "extmod%d" % n |
211 | - print " %s[label=\"%s\"];" % (id, name) |
212 | + print(" %s[label=\"%s\"];" % (id, name)) |
213 | for module in self.modules.values(): |
214 | for other in module.imports: |
215 | - print " %s -> %s;" % (nameDict[module.modname], |
216 | - nameDict[other]); |
217 | - print "}" |
218 | + print(" %s -> %s;" % (nameDict[module.modname], |
219 | + nameDict[other])) |
220 | + print("}") |
221 | |
222 | |
223 | def main(argv=sys.argv): |
224 | @@ -326,8 +330,8 @@ def main(argv=sys.argv): |
225 | ['dot', 'unused', 'all', 'names', 'imports', |
226 | 'help']) |
227 | except getopt.error as e: |
228 | - print >> sys.stderr, "%s: %s" % (progname, e) |
229 | - print >> sys.stderr, "Try %s --help." % progname |
230 | + print("%s: %s" % (progname, e), file=sys.stderr) |
231 | + print("Try %s --help." % progname, file=sys.stderr) |
232 | return 1 |
233 | for k, v in opts: |
234 | if k in ('-d', '--dot'): |
235 | @@ -341,7 +345,7 @@ def main(argv=sys.argv): |
236 | elif k in ('-i', '--imports'): |
237 | action = g.printImports |
238 | elif k in ('-h', '--help'): |
239 | - print helptext |
240 | + print(helptext) |
241 | return 0 |
242 | g.trackUnusedNames = (action == g.printUnusedImports) |
243 | if not args: |
244 | diff --git a/utilities/format-imports b/utilities/format-imports |
245 | index 49cf195..78ecd51 100755 |
246 | --- a/utilities/format-imports |
247 | +++ b/utilities/format-imports |
248 | @@ -125,6 +125,8 @@ is over the length limit. |
249 | }}} |
250 | """ |
251 | |
252 | +from __future__ import absolute_import, print_function |
253 | + |
254 | __metaclass__ = type |
255 | |
256 | # SKIP this file when reformatting. |
257 | @@ -380,7 +382,7 @@ def process_file(fpath): |
258 | """Process the file with the given path.""" |
259 | changed = reformat_importsection(fpath) |
260 | if changed: |
261 | - print fpath |
262 | + print(fpath) |
263 | |
264 | |
265 | def process_tree(dpath): |
266 | diff --git a/utilities/get-branch-info b/utilities/get-branch-info |
267 | index 5143087..34a6b83 100755 |
268 | --- a/utilities/get-branch-info |
269 | +++ b/utilities/get-branch-info |
270 | @@ -8,6 +8,8 @@ |
271 | Usage: get-branch-info <branch_url> |
272 | """ |
273 | |
274 | +from __future__ import absolute_import, print_function |
275 | + |
276 | import _pythonpath |
277 | |
278 | import sys |
279 | @@ -29,21 +31,21 @@ def main(args): |
280 | branch_lookup = getUtility(IBranchLookup) |
281 | branch = branch_lookup.getByUrl(branch_url) |
282 | if branch is None: |
283 | - print "Could not find branch at %r" % (branch_url,) |
284 | + print("Could not find branch at %r" % (branch_url,)) |
285 | return |
286 | - print branch.bzr_identity |
287 | |
288 | - print 'Unique name:', branch.unique_name |
289 | - print 'ID:', branch.id |
290 | - print 'Private:', branch.private |
291 | - print 'Type:', branch.branch_type |
292 | - print 'URL:', canonical_url(branch) |
293 | + print(branch.bzr_identity) |
294 | + print() |
295 | + print('Unique name:', branch.unique_name) |
296 | + print('ID:', branch.id) |
297 | + print('Private:', branch.private) |
298 | + print('Type:', branch.branch_type) |
299 | + print('URL:', canonical_url(branch)) |
300 | if branch.url is not None: |
301 | - print 'External URL:', branch.url |
302 | + print('External URL:', branch.url) |
303 | branch_path = branch_id_to_path(branch.id) |
304 | mirrored_path = join( |
305 | config.codehosting.mirrored_branches_root, branch_path) |
306 | - print 'Mirrored copy:', mirrored_path |
307 | + print('Mirrored copy:', mirrored_path) |
308 | |
309 | |
310 | if __name__ == '__main__': |
311 | diff --git a/utilities/list-pages b/utilities/list-pages |
312 | index 7de2538..c4eaf89 100755 |
313 | --- a/utilities/list-pages |
314 | +++ b/utilities/list-pages |
315 | @@ -42,6 +42,8 @@ because our cheat objects don't match the app-encoded business logic. |
316 | # - bang the adapter nut against the hardest rock we can find until it cracks |
317 | # - print the nourishing nutty goodness to stdout |
318 | |
319 | +from __future__ import absolute_import, print_function |
320 | + |
321 | import _pythonpath |
322 | |
323 | from inspect import getmro |
324 | @@ -244,7 +246,7 @@ def main(): |
325 | gsm = getGlobalSiteManager() |
326 | gsm.registerAdapter(DefaultCanonicalUrlData) |
327 | for a in iter_page_adapters(): |
328 | - print format_page_adapter(a) |
329 | + print(format_page_adapter(a)) |
330 | |
331 | |
332 | if __name__ == '__main__': |
333 | diff --git a/utilities/lsconf.py b/utilities/lsconf.py |
334 | index 9404f29..5137ffc 100755 |
335 | --- a/utilities/lsconf.py |
336 | +++ b/utilities/lsconf.py |
337 | @@ -5,6 +5,8 @@ |
338 | |
339 | """Create lazr.config schema and confs from ZConfig data.""" |
340 | |
341 | +from __future__ import absolute_import, print_function |
342 | + |
343 | __metatype__ = type |
344 | |
345 | # Scripts may have relative imports. |
346 | @@ -70,10 +72,10 @@ class Configuration: |
347 | was defined. |
348 | :param section_name: Only print the named section. |
349 | """ |
350 | - print '# This configuration derives from:' |
351 | + print('# This configuration derives from:') |
352 | for config_data in self.config.overlays: |
353 | - print '# %s' % config_data.filename |
354 | |
355 | + print('# %s' % config_data.filename) |
356 | + print() |
357 | name_key = attrgetter('name') |
358 | for count, section in enumerate(sorted(self.config, key=name_key)): |
359 | if section_name is not None and section_name != section.name: |
360 | @@ -81,17 +83,17 @@ class Configuration: |
361 | if count > 0: |
362 | # Separate sections by a blank line, or two when verbose. |
363 | |
364 | - print '[%s]' % section.name |
365 | + print('[%s]' % section.name) |
366 | if verbose and section.optional: |
367 | - print '# This section is optional.\n' |
368 | + print('# This section is optional.\n') |
369 | for count, key in enumerate(sorted(section)): |
370 | if verbose: |
371 | if count > 0: |
372 | # Separate keys by a blank line. |
373 | |
374 | + print() |
375 | conf_file_name = self.config_file_for_value(section, key) |
376 | - print '# Defined in: %s' % conf_file_name |
377 | - print '%s: %s' % (key, section[key]) |
378 | + print('# Defined in: %s' % conf_file_name) |
379 | + print('%s: %s' % (key, section[key])) |
380 | |
381 | |
382 | def get_option_parser(): |
383 | diff --git a/utilities/make-dummy-hosted-branches b/utilities/make-dummy-hosted-branches |
384 | index 41a45b3..3a7cced 100755 |
385 | --- a/utilities/make-dummy-hosted-branches |
386 | +++ b/utilities/make-dummy-hosted-branches |
387 | @@ -15,6 +15,8 @@ sample data on the filesystem is consistent with the sample data in the |
388 | database. |
389 | """ |
390 | |
391 | +from __future__ import absolute_import, print_function |
392 | + |
393 | import _pythonpath |
394 | |
395 | import os |
396 | @@ -45,7 +47,7 @@ def main(argv): |
397 | make_bazaar_branch_and_tree(branch) |
398 | finally: |
399 | transaction.abort() |
400 | - print "Created %d branches based on sample data." % len(list(branches)) |
401 | + print("Created %d branches based on sample data." % len(list(branches))) |
402 | |
403 | |
404 | if __name__ == '__main__': |
405 | diff --git a/utilities/make-lp-user b/utilities/make-lp-user |
406 | index 0f28da4..fe94a9b 100755 |
407 | --- a/utilities/make-lp-user |
408 | +++ b/utilities/make-lp-user |
409 | @@ -29,6 +29,8 @@ Please note that this script is for testing purposes only. Do NOT use it in |
410 | production environments. |
411 | """ |
412 | |
413 | +from __future__ import absolute_import, print_function |
414 | + |
415 | import _pythonpath |
416 | |
417 | from optparse import OptionParser |
418 | @@ -65,8 +67,8 @@ def make_person(username, email): |
419 | The email address for the user will be <username>@example.com. |
420 | """ |
421 | person = factory.makePerson(name=username, email=email) |
422 | - print "username: %s" % (username,) |
423 | - print "email: %s" % (email,) |
424 | + print("username: %s" % (username,)) |
425 | + print("email: %s" % (email,)) |
426 | return person |
427 | |
428 | |
429 | @@ -83,15 +85,15 @@ def add_person_to_teams(person, team_names): |
430 | for team_name in team_names: |
431 | team = person_set.getByName(team_name) |
432 | if team is None: |
433 | - print "ERROR: %s not found." % (team_name,) |
434 | + print("ERROR: %s not found." % (team_name,)) |
435 | continue |
436 | if not team.is_team: |
437 | - print "ERROR: %s is not a team." % (team_name,) |
438 | + print("ERROR: %s is not a team." % (team_name,)) |
439 | continue |
440 | team.addMember( |
441 | person, person, status=TeamMembershipStatus.APPROVED) |
442 | teams_joined.append(team_name) |
443 | - print "teams: %s" % ' '.join(teams_joined) |
444 | + print("teams: %s" % ' '.join(teams_joined)) |
445 | |
446 | |
447 | def add_ssh_public_keys(person): |
448 | @@ -112,10 +114,10 @@ def add_ssh_public_keys(person): |
449 | except (OSError, IOError): |
450 | continue |
451 | key_set.new(person, public_key) |
452 | - print 'Registered SSH key: %s' % (filename,) |
453 | + print('Registered SSH key: %s' % (filename,)) |
454 | break |
455 | else: |
456 | - print 'No SSH key files found in %s' % ssh_dir |
457 | + print('No SSH key files found in %s' % ssh_dir) |
458 | |
459 | |
460 | def parse_fingerprints(gpg_output): |
461 | @@ -144,7 +146,7 @@ def run_native_gpg(arguments): |
462 | command_line, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
463 | stdout, stderr = pipe.communicate() |
464 | if stderr != '': |
465 | - print stderr |
466 | + print(stderr) |
467 | if pipe.returncode != 0: |
468 | raise Exception('GPG error during "%s"' % ' '.join(command_line)) |
469 | |
470 | @@ -179,7 +181,7 @@ def attach_gpg_keys(email, person): |
471 | |
472 | fingerprints = parse_fingerprints(output) |
473 | if len(fingerprints) == 0: |
474 | - print "No GPG key fingerprints found!" |
475 | + print("No GPG key fingerprints found!") |
476 | for fingerprint in fingerprints: |
477 | add_gpg_key(person, fingerprint) |
478 | |
479 | @@ -197,7 +199,7 @@ def parse_args(arguments): |
480 | |
481 | options, args = parser.parse_args(arguments) |
482 | if len(args) == 0: |
483 | - print __doc__ |
484 | + print(__doc__) |
485 | sys.exit(2) |
486 | |
487 | options.username = args[0] |
488 | diff --git a/utilities/mock-code-import b/utilities/mock-code-import |
489 | index 25e86d0..dd0f2dc 100755 |
490 | --- a/utilities/mock-code-import |
491 | +++ b/utilities/mock-code-import |
492 | @@ -20,6 +20,8 @@ Details of the Subversion server are printed to stdout. |
493 | # XXX: JonathanLange 2008-01-03: This is deliberately horrible. |
494 | # You can make it nicer if you want. |
495 | |
496 | +from __future__ import absolute_import, print_function |
497 | + |
498 | import _pythonpath |
499 | |
500 | import os |
501 | @@ -38,7 +40,7 @@ from lp.testing.factory import LaunchpadObjectFactory |
502 | |
503 | |
504 | def shell(*args): |
505 | - print ' '.join(args) |
506 | + print(' '.join(args)) |
507 | return Popen(args, stdout=PIPE).communicate()[0] |
508 | |
509 | |
510 | @@ -59,12 +61,12 @@ def main(): |
511 | 'trunk', [('README', 'No real content\n.')]) |
512 | job = make_import_job(svn_url) |
513 | transaction.commit() |
514 | - print "CodeImportJob.id:", job.id |
515 | - print "Code Import URL:", canonical_url(job.code_import) |
516 | - print "Subversion Repository:", svn_repo_path |
517 | - print "Subversion branch URL:", job.code_import.svn_branch_url |
518 | - print "Launchpad branch URL:", canonical_url(job.code_import.branch) |
519 | |
520 | + print("CodeImportJob.id:", job.id) |
521 | + print("Code Import URL:", canonical_url(job.code_import)) |
522 | + print("Subversion Repository:", svn_repo_path) |
523 | + print("Subversion branch URL:", job.code_import.svn_branch_url) |
524 | + print("Launchpad branch URL:", canonical_url(job.code_import.branch)) |
525 | + print() |
526 | finally: |
527 | svn_server.tearDown() |
528 | |
529 | diff --git a/utilities/paste b/utilities/paste |
530 | index e2c630e..e602293 100755 |
531 | --- a/utilities/paste |
532 | +++ b/utilities/paste |
533 | @@ -3,6 +3,8 @@ |
534 | # Copyright 2009-2012 Canonical Ltd. This software is licensed under the |
535 | # GNU Affero General Public License version 3 (see the file LICENSE). |
536 | |
537 | +from __future__ import absolute_import, print_function |
538 | + |
539 | import _pythonpath |
540 | |
541 | import base64 |
542 | @@ -123,7 +125,7 @@ def main(): |
543 | # Figure out the authentication. |
544 | lp_cookie = get_lp_auth_cookie(AUTH_FILE) |
545 | if lp_cookie is None: |
546 | - print LP_AUTH_INSTRUCTIONS |
547 | + print(LP_AUTH_INSTRUCTIONS) |
548 | return |
549 | browser.testapp.cookiejar.set_cookie(lp_cookie) |
550 | |
551 | @@ -140,12 +142,12 @@ def main(): |
552 | if oid_form is not None: |
553 | authenticated = authenticate(browser) |
554 | if not authenticated: |
555 | - print LP_AUTH_INSTRUCTIONS |
556 | + print(LP_AUTH_INSTRUCTIONS) |
557 | return |
558 | for name, value in form: |
559 | browser.getControl(name=name).value = value |
560 | browser.getControl('Paste!').click() |
561 | - print browser.url |
562 | + print(browser.url) |
563 | if parser.options.browser: |
564 | webbrowser.open(browser.url) |
565 | |
566 | diff --git a/utilities/pgcreate.py b/utilities/pgcreate.py |
567 | index 876aa64..fb7aa2d 100755 |
568 | --- a/utilities/pgcreate.py |
569 | +++ b/utilities/pgcreate.py |
570 | @@ -8,6 +8,8 @@ |
571 | Like createdb, except will retry on failure. |
572 | .""" |
573 | |
574 | +from __future__ import absolute_import, print_function |
575 | + |
576 | __metaclass__ = type |
577 | |
578 | import sys |
579 | @@ -18,7 +20,7 @@ import psycopg2 |
580 | |
581 | def main(): |
582 | if len(sys.argv) != 3: |
583 | - print >> sys.stderr, 'Usage: %s [template] [dbname]' % sys.argv[0] |
584 | + print('Usage: %s [template] [dbname]' % sys.argv[0], file=sys.stderr) |
585 | return 1 |
586 | |
587 | template, dbname = sys.argv[1:] |
588 | diff --git a/utilities/pgkillactive.py b/utilities/pgkillactive.py |
589 | index 7729af1..86a94e9 100755 |
590 | --- a/utilities/pgkillactive.py |
591 | +++ b/utilities/pgkillactive.py |
592 | @@ -6,6 +6,8 @@ |
593 | """Kill transaction that have hung around for too long. |
594 | """ |
595 | |
596 | +from __future__ import absolute_import, print_function |
597 | + |
598 | __metaclass__ = type |
599 | __all__ = [] |
600 | |
601 | @@ -66,13 +68,13 @@ def main(): |
602 | |
603 | if len(rows) == 0: |
604 | if not options.quiet: |
605 | - print 'No transactions to kill' |
606 | + print('No transactions to kill') |
607 | return 0 |
608 | |
609 | for usename, pid, backend_start, transaction_start in rows: |
610 | - print 'Killing %s (%d), %s, %s' % ( |
611 | + print('Killing %s (%d), %s, %s' % ( |
612 | usename, pid, backend_start, transaction_start, |
613 | - ) |
614 | + )) |
615 | if not options.dry_run: |
616 | os.kill(pid, signal.SIGTERM) |
617 | return 0 |
618 | diff --git a/utilities/pgkillidle.py b/utilities/pgkillidle.py |
619 | index ec16e03..1c2f70c 100755 |
620 | --- a/utilities/pgkillidle.py |
621 | +++ b/utilities/pgkillidle.py |
622 | @@ -6,6 +6,8 @@ |
623 | """Kill <IDLE> in transaction connections that have hung around for too long. |
624 | """ |
625 | |
626 | +from __future__ import absolute_import, print_function |
627 | + |
628 | __metaclass__ = type |
629 | __all__ = [] |
630 | |
631 | @@ -64,13 +66,13 @@ def main(): |
632 | |
633 | if len(rows) == 0: |
634 | if not options.quiet: |
635 | - print 'No IDLE transactions to kill' |
636 | + print('No IDLE transactions to kill') |
637 | return 0 |
638 | |
639 | for usename, pid, backend_start, query_start in rows: |
640 | - print 'Killing %s(%d), %s, %s' % ( |
641 | + print('Killing %s(%d), %s, %s' % ( |
642 | usename, pid, backend_start, query_start, |
643 | - ) |
644 | + )) |
645 | if not options.dryrun: |
646 | os.kill(pid, signal.SIGTERM) |
647 | return 0 |
648 | diff --git a/utilities/pglogwatch.py b/utilities/pglogwatch.py |
649 | index 49296d1..eb44669 100755 |
650 | --- a/utilities/pglogwatch.py |
651 | +++ b/utilities/pglogwatch.py |
652 | @@ -7,6 +7,8 @@ |
653 | Watch live PostgreSQL logs for interesting stuff |
654 | """ |
655 | |
656 | +from __future__ import absolute_import, print_function |
657 | + |
658 | from optparse import OptionParser |
659 | import re |
660 | import subprocess |
661 | @@ -34,7 +36,7 @@ def generate_loglines(logfile): |
662 | while cmd.poll() is None: |
663 | yield cmd.stdout.readline() |
664 | if cmd.returncode != 0: |
665 | - print >> sys.stderr, cmd.stderr.read() |
666 | + print(cmd.stderr.read(), file=sys.stderr) |
667 | raise RuntimeError("tail returned %d" % cmd.returncode) |
668 | |
669 | |
670 | @@ -158,8 +160,8 @@ class Watcher(object): |
671 | return |
672 | |
673 | if process.duration > options.slow: |
674 | - print '[%5d] %s' % (process.pid, process.statement) |
675 | - print ' Duration: %0.3f' % (process.duration,) |
676 | + print('[%5d] %s' % (process.pid, process.statement)) |
677 | + print(' Duration: %0.3f' % (process.duration,)) |
678 | |
679 | if __name__ == '__main__': |
680 | options = get_options() |
681 | diff --git a/utilities/pgmassacre.py b/utilities/pgmassacre.py |
682 | index ba22ce1..460cc31 100755 |
683 | --- a/utilities/pgmassacre.py |
684 | +++ b/utilities/pgmassacre.py |
685 | @@ -13,6 +13,8 @@ Cut off access, slaughter connections and burn the database to the ground |
686 | (but do nothing that could put the system into recovery mode). |
687 | """ |
688 | |
689 | +from __future__ import absolute_import, print_function |
690 | + |
691 | import _pythonpath |
692 | |
693 | from optparse import OptionParser |
694 | @@ -115,13 +117,14 @@ def massacre(database): |
695 | """ % activity_cols(cur), [database]) |
696 | for pid, success in cur.fetchall(): |
697 | if not success: |
698 | - print >> sys.stderr, ( |
699 | - "pg_terminate_backend(%s) failed" % pid) |
700 | + print( |
701 | + "pg_terminate_backend(%s) failed" % pid, file=sys.stderr) |
702 | con.close() |
703 | |
704 | if still_open(database): |
705 | - print >> sys.stderr, ( |
706 | - "Unable to kill all backends! Database not destroyed.") |
707 | + print( |
708 | + "Unable to kill all backends! Database not destroyed.", |
709 | + file=sys.stderr) |
710 | return 9 |
711 | |
712 | # Destroy the database. |
713 | @@ -146,8 +149,9 @@ def massacre(database): |
714 | |
715 | def rebuild(database, template): |
716 | if still_open(template, 20): |
717 | - print >> sys.stderr, ( |
718 | - "Giving up waiting for connections to %s to drop." % template) |
719 | + print( |
720 | + "Giving up waiting for connections to %s to drop." % template, |
721 | + file=sys.stderr) |
722 | report_open_connections(template) |
723 | return 10 |
724 | |
725 | @@ -178,7 +182,7 @@ def rebuild(database, template): |
726 | now = time.time() |
727 | con.close() |
728 | |
729 | - print >> sys.stderr, "Unable to recreate database: %s" % error_msg |
730 | + print("Unable to recreate database: %s" % error_msg, file=sys.stderr) |
731 | return 11 |
732 | |
733 | |
734 | @@ -193,8 +197,9 @@ def report_open_connections(database): |
735 | ORDER BY datname, usename |
736 | """ % activity_cols(cur)) |
737 | for usename, datname, num_connections in cur.fetchall(): |
738 | - print >> sys.stderr, "%d connections by %s to %s" % ( |
739 | - num_connections, usename, datname) |
740 | + print( |
741 | + "%d connections by %s to %s" % (num_connections, usename, datname), |
742 | + file=sys.stderr) |
743 | con.close() |
744 | |
745 | |
746 | @@ -241,7 +246,7 @@ def main(): |
747 | if db_exists: |
748 | rv = massacre(database) |
749 | if rv != 0: |
750 | - print >> sys.stderr, "Fail %d" % rv |
751 | + print("Fail %d" % rv, file=sys.stderr) |
752 | return rv |
753 | |
754 | if options.template is not None: |
755 | diff --git a/utilities/pgstats.py b/utilities/pgstats.py |
756 | index 4c1691f..248b52c 100755 |
757 | --- a/utilities/pgstats.py |
758 | +++ b/utilities/pgstats.py |
759 | @@ -8,6 +8,8 @@ Generate some statistics about a PostgreSQL database suitable for |
760 | emailing via cron |
761 | """ |
762 | |
763 | +from __future__ import absolute_import, print_function |
764 | + |
765 | __metaclass__ = type |
766 | |
767 | import sys |
768 | @@ -24,7 +26,7 @@ def percentage(num, total): |
769 | |
770 | |
771 | def print_row(key, value): |
772 | - print '%(key)-20s: %(value)s' % vars() |
773 | + print('%(key)-20s: %(value)s' % vars()) |
774 | |
775 | |
776 | def pgstattuple(cur, table): |
777 | @@ -56,8 +58,8 @@ def main(dbname): |
778 | con = psycopg2.connect("dbname=%s" % dbname) |
779 | cur = con.cursor() |
780 | |
781 | - print 'Statistics for %s' % dbname |
782 | - print '===============' + '=' * (len(dbname)) |
783 | + print('Statistics for %s' % dbname) |
784 | + print('===============' + '=' * (len(dbname))) |
785 | |
786 | # Database level statistics |
787 | cur.execute(""" |
788 | @@ -146,7 +148,7 @@ def main(dbname): |
789 | |
790 | if __name__ == '__main__': |
791 | if len(sys.argv) != 2: |
792 | - print >> sys.stderr, "Usage: %s [DBNAME]" % sys.argv[0] |
793 | + print("Usage: %s [DBNAME]" % sys.argv[0], file=sys.stderr) |
794 | sys.exit(1) |
795 | dbname = sys.argv[1] |
796 | main(dbname) |
797 | diff --git a/utilities/report-database-stats.py b/utilities/report-database-stats.py |
798 | index 7580bb1..3b171de 100755 |
799 | --- a/utilities/report-database-stats.py |
800 | +++ b/utilities/report-database-stats.py |
801 | @@ -4,6 +4,8 @@ |
802 | |
803 | """Generate the database statistics report.""" |
804 | |
805 | +from __future__ import absolute_import, print_function |
806 | + |
807 | __metaclass__ = type |
808 | |
809 | import _pythonpath |
810 | @@ -268,25 +270,25 @@ def main(): |
811 | parser.error("Only one sample in that time range.") |
812 | |
813 | user_cpu = get_cpu_stats(cur, options) |
814 | - print "== Most Active Users ==" |
815 | |
816 | + print("== Most Active Users ==") |
817 | + print() |
818 | for cpu, username in sorted(user_cpu, reverse=True)[:options.limit]: |
819 | - print "%40s || %10.2f%% CPU" % (username, float(cpu) / 10) |
820 | + print("%40s || %10.2f%% CPU" % (username, float(cpu) / 10)) |
821 | |
822 | |
823 | - print "== Most Written Tables ==" |
824 | |
825 | + print() |
826 | + print("== Most Written Tables ==") |
827 | + print() |
828 | tables_sort = [ |
829 | 'total_tup_written', 'n_tup_upd', 'n_tup_ins', 'n_tup_del', 'relname'] |
830 | most_written_tables = sorted( |
831 | tables, key=attrgetter(*tables_sort), reverse=True) |
832 | for table in most_written_tables[:options.limit]: |
833 | - print "%40s || %10.2f tuples/sec" % ( |
834 | - table.relname, table.total_tup_written / per_second) |
835 | + print("%40s || %10.2f tuples/sec" % ( |
836 | + table.relname, table.total_tup_written / per_second)) |
837 | |
838 | |
839 | - print "== Most Read Tables ==" |
840 | |
841 | + print() |
842 | + print("== Most Read Tables ==") |
843 | + print() |
844 | # These match the pg_user_table_stats view. schemaname is the |
845 | # namespace (normally 'public'), relname is the table (relation) |
846 | # name. total_tup_red is the total number of rows read. |
847 | @@ -295,37 +297,37 @@ def main(): |
848 | most_read_tables = sorted( |
849 | tables, key=attrgetter(*tables_sort), reverse=True) |
850 | for table in most_read_tables[:options.limit]: |
851 | - print "%40s || %10.2f tuples/sec" % ( |
852 | - table.relname, table.total_tup_read / per_second) |
853 | + print("%40s || %10.2f tuples/sec" % ( |
854 | + table.relname, table.total_tup_read / per_second)) |
855 | |
856 | table_bloat_stats = get_bloat_stats(cur, options, 'r') |
857 | |
858 | if not table_bloat_stats: |
859 | |
860 | - print "(There is no bloat information available in this time range.)" |
861 | + print() |
862 | + print("(There is no bloat information available in this time range.)") |
863 | |
864 | else: |
865 | |
866 | - print "== Most Bloated Tables ==" |
867 | |
868 | + print() |
869 | + print("== Most Bloated Tables ==") |
870 | + print() |
871 | for bloated_table in table_bloat_stats[:options.limit]: |
872 | - print "%40s || %2d%% || %s of %s" % ( |
873 | + print("%40s || %2d%% || %s of %s" % ( |
874 | bloated_table.name, |
875 | bloated_table.end_bloat_percent, |
876 | bloated_table.bloat_size, |
877 | - bloated_table.table_size) |
878 | + bloated_table.table_size)) |
879 | |
880 | index_bloat_stats = get_bloat_stats(cur, options, 'i') |
881 | |
882 | |
883 | - print "== Most Bloated Indexes ==" |
884 | |
885 | + print() |
886 | + print("== Most Bloated Indexes ==") |
887 | + print() |
888 | for bloated_index in index_bloat_stats[:options.limit]: |
889 | - print "%65s || %2d%% || %s of %s" % ( |
890 | + print("%65s || %2d%% || %s of %s" % ( |
891 | bloated_index.sub_name, |
892 | bloated_index.end_bloat_percent, |
893 | bloated_index.bloat_size, |
894 | - bloated_index.table_size) |
895 | + bloated_index.table_size)) |
896 | |
897 | # Order bloat delta report by size of bloat increase. |
898 | # We might want to change this to percentage bloat increase. |
899 | @@ -335,39 +337,39 @@ def main(): |
900 | table_bloat_stats, key=bloating_sort_key, reverse=True) |
901 | |
902 | if table_bloating_stats[0].num_samples <= 1: |
903 | |
904 | - print fill(dedent("""\ |
905 | + print() |
906 | + print(fill(dedent("""\ |
907 | (There are not enough samples in this time range to display |
908 | bloat change statistics) |
909 | - """)) |
910 | + """))) |
911 | else: |
912 | |
913 | - print "== Most Bloating Tables ==" |
914 | |
915 | + print() |
916 | + print("== Most Bloating Tables ==") |
917 | + print() |
918 | |
919 | for bloated_table in table_bloating_stats[:options.limit]: |
920 | # Bloat decreases are uninteresting, and would need to be in |
921 | # a separate table sorted in reverse anyway. |
922 | if bloated_table.delta_bloat_percent > 0: |
923 | - print "%40s || +%4.2f%% || +%s" % ( |
924 | + print("%40s || +%4.2f%% || +%s" % ( |
925 | bloated_table.name, |
926 | bloated_table.delta_bloat_percent, |
927 | - bloated_table.delta_bloat_size) |
928 | + bloated_table.delta_bloat_size)) |
929 | |
930 | index_bloating_stats = sorted( |
931 | index_bloat_stats, key=bloating_sort_key, reverse=True) |
932 | |
933 | |
934 | - print "== Most Bloating Indexes ==" |
935 | |
936 | + print() |
937 | + print("== Most Bloating Indexes ==") |
938 | + print() |
939 | for bloated_index in index_bloating_stats[:options.limit]: |
940 | # Bloat decreases are uninteresting, and would need to be in |
941 | # a separate table sorted in reverse anyway. |
942 | if bloated_index.delta_bloat_percent > 0: |
943 | - print "%65s || +%4.2f%% || +%s" % ( |
944 | + print("%65s || +%4.2f%% || +%s" % ( |
945 | bloated_index.sub_name, |
946 | bloated_index.delta_bloat_percent, |
947 | - bloated_index.delta_bloat_size) |
948 | + bloated_index.delta_bloat_size)) |
949 | |
950 | |
951 | if __name__ == '__main__': |
952 | diff --git a/utilities/shhh.py b/utilities/shhh.py |
953 | index 6b9c1f6..f610f9a 100755 |
954 | --- a/utilities/shhh.py |
955 | +++ b/utilities/shhh.py |
956 | @@ -48,7 +48,7 @@ def shhh(cmd): |
957 | >>> shhh_script(cmd) |
958 | ('', '', 1) |
959 | |
960 | - >>> cmd = [python, "-c", "import sys; print 666; sys.exit(42)"] |
961 | + >>> cmd = [python, "-c", "import sys; print(666); sys.exit(42)"] |
962 | >>> shhh(cmd) |
963 | 666 |
964 | 42 |
965 | @@ -57,7 +57,9 @@ def shhh(cmd): |
966 | |
967 | >>> cmd = [ |
968 | ... python, "-c", |
969 | - ... "import sys; print 666; print >> sys.stderr, 667; sys.exit(42)", |
970 | + ... "from __future__ import print_function; " |
971 | + ... "import sys; " |
972 | + ... "print(666); print(667, file=sys.stderr); sys.exit(42)", |
973 | ... ] |
974 | >>> shhh_script(cmd) |
975 | ('666\n', '667\n', 42) |
976 | diff --git a/utilities/soyuz-sampledata-setup.py b/utilities/soyuz-sampledata-setup.py |
977 | index 8f9b80b..8f84752 100755 |
978 | --- a/utilities/soyuz-sampledata-setup.py |
979 | +++ b/utilities/soyuz-sampledata-setup.py |
980 | @@ -17,6 +17,8 @@ This script creates a user "ppa-user" (email ppa-user@example.com, |
981 | password test) who is able to create PPAs. |
982 | """ |
983 | |
984 | +from __future__ import absolute_import, print_function |
985 | + |
986 | __metaclass__ = type |
987 | |
988 | import _pythonpath |
989 | @@ -342,7 +344,7 @@ def create_ppa_user(username, options, approver, log): |
990 | pipe = subprocess.Popen(command_line, stderr=subprocess.PIPE) |
991 | stdout, stderr = pipe.communicate() |
992 | if stderr != '': |
993 | - print stderr |
994 | + print(stderr) |
995 | if pipe.returncode != 0: |
996 | sys.exit(2) |
997 | |
998 | @@ -396,7 +398,7 @@ class SoyuzSampledataSetup(LaunchpadScript): |
999 | transaction.commit() |
1000 | self.logger.info("Done.") |
1001 | |
1002 | - print dedent(""" |
1003 | + print(dedent(""" |
1004 | Now start your local Launchpad with "make run_codehosting" and log |
1005 | into https://launchpad.test/ as "%(email)s" with "test" as the |
1006 | password. |
1007 | @@ -404,7 +406,7 @@ class SoyuzSampledataSetup(LaunchpadScript): |
1008 | % { |
1009 | 'email': self.options.email, |
1010 | 'user_name': user_name, |
1011 | - }) |
1012 | + })) |
1013 | |
1014 | |
1015 | if __name__ == "__main__": |
1016 | diff --git a/utilities/update-copyright b/utilities/update-copyright |
1017 | index c2e0236..5df0212 100755 |
1018 | --- a/utilities/update-copyright |
1019 | +++ b/utilities/update-copyright |
1020 | @@ -10,6 +10,8 @@ notice to reflect the current year. Looks for the notice in the first three |
1021 | lines of the file and leaves the file unchanged if it finds none. |
1022 | """ |
1023 | |
1024 | +from __future__ import absolute_import, print_function |
1025 | + |
1026 | from datetime import date |
1027 | import os |
1028 | import re |
1029 | @@ -49,11 +51,11 @@ def update_files(filenames): |
1030 | """Open the files with the given file names and update them.""" |
1031 | for filename in filenames: |
1032 | if not os.path.isfile(filename): |
1033 | - print "Skipped: %s does not exist or is not a regular file." %( |
1034 | - filename) |
1035 | + print("Skipped: %s does not exist or is not a regular file." %( |
1036 | + filename)) |
1037 | continue |
1038 | if not os.access(filename, os.W_OK): |
1039 | - print "Skipped: %s is not writeable." % filename |
1040 | + print("Skipped: %s is not writeable." % filename) |
1041 | continue |
1042 | lines = file(filename).readlines() |
1043 | changed = update_copyright(lines) |
1044 | @@ -61,9 +63,9 @@ def update_files(filenames): |
1045 | newfile = open(filename, 'w') |
1046 | newfile.write(''.join(lines)) |
1047 | newfile.close() |
1048 | - print "Updated: %s" % filename |
1049 | + print("Updated: %s" % filename) |
1050 | else: |
1051 | - print "Unchanged: %s" % filename |
1052 | + print("Unchanged: %s" % filename) |
1053 | |
1054 | def find_changed_files(): |
1055 | """Use the find-changed-files.sh script.""" |
Self-approving (a bit bulky, but essentially mechanical; no functional change on Python 2).