Merge ~cjwatson/launchpad:scripts-future-imports into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: e14333cc77e822297ae7c6d555df07c5d71c863b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:scripts-future-imports
Merge into: launchpad:master
Prerequisite: ~cjwatson/launchpad:scripts-utilities-js-future-imports
Diff against target: 508 lines (+97/-67)
16 files modified
lib/lp/scripts/garbo.py (+3/-1)
lib/lp/scripts/harness.py (+2/-0)
lib/lp/scripts/helpers.py (+2/-0)
lib/lp/scripts/runlaunchpad.py (+10/-8)
lib/lp/scripts/scriptmonitor.py (+2/-0)
lib/lp/scripts/tests/test_garbo.py (+42/-41)
lib/lp/scripts/tests/test_helpers.py (+2/-0)
lib/lp/scripts/tests/test_runlaunchpad.py (+2/-0)
lib/lp/scripts/tests/test_scriptmonitor.py (+2/-0)
lib/lp/scripts/tests/test_sphinxdocs.py (+2/-0)
lib/lp/scripts/utilities/importpedant.py (+18/-16)
lib/lp/scripts/utilities/killservice.py (+2/-1)
lib/lp/scripts/utilities/settingsauditor.py (+2/-0)
lib/lp/scripts/utilities/test.py (+2/-0)
lib/lp/scripts/utilities/tests/test_audit_security_settings.py (+2/-0)
lib/lp/scripts/utilities/tests/test_shhh.py (+2/-0)
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+377137@code.launchpad.net

Commit message

Convert lp.scripts to preferred __future__ imports

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
2index b6b5f27..6f6ad6b 100644
3--- a/lib/lp/scripts/garbo.py
4+++ b/lib/lp/scripts/garbo.py
5@@ -3,6 +3,8 @@
6
7 """Database garbage collection."""
8
9+from __future__ import absolute_import, print_function, unicode_literals
10+
11 __metaclass__ = type
12 __all__ = [
13 'DailyDatabaseGarbageCollector',
14@@ -456,7 +458,7 @@ class VoucherRedeemer(TunableLoop):
15 def _pending_subscriptions(self):
16 return self.store.find(
17 CommercialSubscription,
18- Like(CommercialSubscription.sales_system_id, u'pending-%')
19+ Like(CommercialSubscription.sales_system_id, 'pending-%')
20 )
21
22 def isDone(self):
23diff --git a/lib/lp/scripts/harness.py b/lib/lp/scripts/harness.py
24index 45c23c7..7bfe67e 100644
25--- a/lib/lp/scripts/harness.py
26+++ b/lib/lp/scripts/harness.py
27@@ -9,6 +9,8 @@ launchpad_dev or the database specified on the command line.
28 One uses Python, the other iPython.
29 """
30
31+from __future__ import absolute_import, print_function, unicode_literals
32+
33 __metaclass__ = type
34 __all__ = ['python', 'ipython']
35
36diff --git a/lib/lp/scripts/helpers.py b/lib/lp/scripts/helpers.py
37index a534c6c..99922c3 100644
38--- a/lib/lp/scripts/helpers.py
39+++ b/lib/lp/scripts/helpers.py
40@@ -3,6 +3,8 @@
41
42 """Helpers for command line tools."""
43
44+from __future__ import absolute_import, print_function, unicode_literals
45+
46 __metaclass__ = type
47 __all__ = ["LPOptionParser", "TransactionFreeOperation", ]
48
49diff --git a/lib/lp/scripts/runlaunchpad.py b/lib/lp/scripts/runlaunchpad.py
50index b66e26f..9fc5add 100644
51--- a/lib/lp/scripts/runlaunchpad.py
52+++ b/lib/lp/scripts/runlaunchpad.py
53@@ -1,6 +1,8 @@
54 # Copyright 2009-2019 Canonical Ltd. This software is licensed under the
55 # GNU Affero General Public License version 3 (see the file LICENSE).
56
57+from __future__ import absolute_import, print_function, unicode_literals
58+
59 __metaclass__ = type
60 __all__ = ['start_launchpad']
61
62@@ -377,9 +379,9 @@ def start_testapp(argv=list(sys.argv)):
63 teardowns.append(LayerProcessController.stopSMTPServer)
64 if interactive_tests:
65 root_url = config.appserver_root_url()
66- print '*' * 70
67- print 'In a few seconds, go to ' + root_url + '/+yuitest'
68- print '*' * 70
69+ print('*' * 70)
70+ print('In a few seconds, go to ' + root_url + '/+yuitest')
71+ print('*' * 70)
72 try:
73 start_launchpad(argv, setup)
74 finally:
75@@ -422,19 +424,19 @@ def start_launchpad(argv=list(sys.argv), setup=None):
76 except KeyboardInterrupt:
77 pass
78 except Exception as e:
79- print >> sys.stderr, "stopping services on exception %r" % e
80+ print("stopping services on exception %r" % e, file=sys.stderr)
81 for service in services:
82- print >> sys.stderr, service, "fixture details:"
83+ print(service, "fixture details:", file=sys.stderr)
84 # There may be no details on some services if they haven't been
85 # initialized yet.
86 if getattr(service, '_details', None) is None:
87- print >> sys.stderr, "(not ready yet?)"
88+ print("(not ready yet?)", file=sys.stderr)
89 continue
90 details_str = _details_to_str(service.getDetails())
91 if details_str:
92- print >> sys.stderr, details_str
93+ print(details_str, file=sys.stderr)
94 else:
95- print >> sys.stderr, "(no details present)"
96+ print("(no details present)", file=sys.stderr)
97 raise
98
99
100diff --git a/lib/lp/scripts/scriptmonitor.py b/lib/lp/scripts/scriptmonitor.py
101index 72dad3e..57b1426 100644
102--- a/lib/lp/scripts/scriptmonitor.py
103+++ b/lib/lp/scripts/scriptmonitor.py
104@@ -3,6 +3,8 @@
105
106 """Monitor whether scripts have run between specified time periods."""
107
108+from __future__ import absolute_import, print_function, unicode_literals
109+
110 __metaclass__ = type
111 __all__ = ['check_script']
112
113diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
114index 329b8fc..e0cb87e 100644
115--- a/lib/lp/scripts/tests/test_garbo.py
116+++ b/lib/lp/scripts/tests/test_garbo.py
117@@ -3,6 +3,8 @@
118
119 """Test the database garbage collector."""
120
121+from __future__ import absolute_import, print_function, unicode_literals
122+
123 __metaclass__ = type
124 __all__ = []
125
126@@ -274,12 +276,12 @@ class TestSessionPruner(TestCase):
127 yesterday = recent - timedelta(days=1)
128 ancient = recent - timedelta(days=61)
129
130- self.make_session(u'recent_auth', recent, 'auth1')
131- self.make_session(u'recent_unauth', recent, False)
132- self.make_session(u'yesterday_auth', yesterday, 'auth2')
133- self.make_session(u'yesterday_unauth', yesterday, False)
134- self.make_session(u'ancient_auth', ancient, 'auth3')
135- self.make_session(u'ancient_unauth', ancient, False)
136+ self.make_session('recent_auth', recent, b'auth1')
137+ self.make_session('recent_unauth', recent, False)
138+ self.make_session('yesterday_auth', yesterday, b'auth2')
139+ self.make_session('yesterday_unauth', yesterday, False)
140+ self.make_session('ancient_auth', ancient, b'auth3')
141+ self.make_session('ancient_unauth', ancient, False)
142
143 self.log = logging.getLogger('garbo')
144
145@@ -293,16 +295,16 @@ class TestSessionPruner(TestCase):
146 # Add login time information.
147 session_pkg_data = SessionPkgData()
148 session_pkg_data.client_id = client_id
149- session_pkg_data.product_id = u'launchpad.authenticateduser'
150- session_pkg_data.key = u'logintime'
151- session_pkg_data.pickle = 'value is ignored'
152+ session_pkg_data.product_id = 'launchpad.authenticateduser'
153+ session_pkg_data.key = 'logintime'
154+ session_pkg_data.pickle = b'value is ignored'
155 IMasterStore(SessionPkgData).add(session_pkg_data)
156
157 # Add authenticated as information.
158 session_pkg_data = SessionPkgData()
159 session_pkg_data.client_id = client_id
160- session_pkg_data.product_id = u'launchpad.authenticateduser'
161- session_pkg_data.key = u'accountid'
162+ session_pkg_data.product_id = 'launchpad.authenticateduser'
163+ session_pkg_data.key = 'accountid'
164 # Normally Account.id, but the session pruning works
165 # at the SQL level and doesn't unpickle anything.
166 session_pkg_data.pickle = authenticated
167@@ -323,12 +325,12 @@ class TestSessionPruner(TestCase):
168 pruner.cleanUp()
169
170 expected_sessions = set([
171- u'recent_auth',
172- u'recent_unauth',
173- u'yesterday_auth',
174- u'yesterday_unauth',
175- # u'ancient_auth',
176- # u'ancient_unauth',
177+ 'recent_auth',
178+ 'recent_unauth',
179+ 'yesterday_auth',
180+ 'yesterday_unauth',
181+ # 'ancient_auth',
182+ # 'ancient_unauth',
183 ])
184
185 found_sessions = set(
186@@ -346,12 +348,12 @@ class TestSessionPruner(TestCase):
187 pruner.cleanUp()
188
189 expected_sessions = set([
190- u'recent_auth',
191- u'recent_unauth',
192- u'yesterday_auth',
193- # u'yesterday_unauth',
194- u'ancient_auth',
195- # u'ancient_unauth',
196+ 'recent_auth',
197+ 'recent_unauth',
198+ 'yesterday_auth',
199+ # 'yesterday_unauth',
200+ 'ancient_auth',
201+ # 'ancient_unauth',
202 ])
203
204 found_sessions = set(
205@@ -363,12 +365,12 @@ class TestSessionPruner(TestCase):
206 # None of the sessions created in setUp() are duplicates, so
207 # they will all survive the pruning.
208 expected_sessions = set([
209- u'recent_auth',
210- u'recent_unauth',
211- u'yesterday_auth',
212- u'yesterday_unauth',
213- u'ancient_auth',
214- u'ancient_unauth',
215+ 'recent_auth',
216+ 'recent_unauth',
217+ 'yesterday_auth',
218+ 'yesterday_unauth',
219+ 'ancient_auth',
220+ 'ancient_unauth',
221 ])
222
223 now = datetime.now(UTC)
224@@ -378,17 +380,17 @@ class TestSessionPruner(TestCase):
225 # most recent 'old dupe 1'.
226 for count in range(1, 10):
227 self.make_session(
228- u'old dupe %d' % count,
229+ 'old dupe %d' % count,
230 now - timedelta(days=2, seconds=count),
231- 'old dupe')
232+ b'old dupe')
233 for count in range(1, 7):
234- expected_sessions.add(u'old dupe %d' % count)
235+ expected_sessions.add('old dupe %d' % count)
236
237 # Make some other duplicate logins less than an hour old.
238 # All of these will be kept.
239 for count in range(1, 10):
240- self.make_session(u'new dupe %d' % count, now, 'new dupe')
241- expected_sessions.add(u'new dupe %d' % count)
242+ self.make_session('new dupe %d' % count, now, b'new dupe')
243+ expected_sessions.add('new dupe %d' % count)
244
245 chunk_size = 2
246 pruner = DuplicateSessionPruner(self.log)
247@@ -483,8 +485,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
248 self.assertEqual(store.find(OpenIDConsumerNonce).count(), 0)
249
250 for timestamp in timestamps:
251- store.add(OpenIDConsumerNonce(
252- u'http://server/', timestamp, u'aa'))
253+ store.add(OpenIDConsumerNonce('http://server/', timestamp, 'aa'))
254 transaction.commit()
255
256 # Make sure we have 4 nonces now.
257@@ -1171,7 +1172,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
258 # There should now be 0 pending vouchers in Launchpad.
259 num_rows = IMasterStore(CommercialSubscription).find(
260 CommercialSubscription,
261- Like(CommercialSubscription.sales_system_id, u'pending-%')
262+ Like(CommercialSubscription.sales_system_id, 'pending-%')
263 ).count()
264 self.assertThat(num_rows, Equals(0))
265 # Salesforce should also now have redeemed the voucher.
266@@ -1268,7 +1269,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
267 naked_bug = removeSecurityProxy(bug)
268 naked_bug.heat_last_updated = old_update
269 IMasterStore(FeatureFlag).add(FeatureFlag(
270- u'default', 0, u'bugs.heat_updates.cutoff',
271+ 'default', 0, 'bugs.heat_updates.cutoff',
272 cutoff.isoformat().decode('ascii')))
273 transaction.commit()
274 self.assertEqual(old_update, naked_bug.heat_last_updated)
275@@ -1452,7 +1453,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
276 self.assertIsNotNone(
277 store.execute(
278 'SELECT * FROM GarboJobState WHERE name=?',
279- params=[u'PopulateLatestPersonSourcePackageReleaseCache']
280+ params=['PopulateLatestPersonSourcePackageReleaseCache']
281 ).get_one())
282
283 def _assert_releases_by_creator(creator, sprs):
284@@ -1527,7 +1528,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
285 # test LiveFS file as a base image for its DAS.
286 now = datetime.now(UTC)
287 switch_dbuser('testadmin')
288- self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: u'on'}))
289+ self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: 'on'}))
290 store = IMasterStore(LiveFSFile)
291 initial_count = store.find(LiveFSFile).count()
292
293@@ -1596,7 +1597,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
294 # An old LiveFS binary file is pruned even if some other base image
295 # exists.
296 switch_dbuser('testadmin')
297- self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: u'on'}))
298+ self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: 'on'}))
299 store = IMasterStore(LiveFSFile)
300 other_build = self.factory.makeLiveFSBuild(
301 status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=10))
302diff --git a/lib/lp/scripts/tests/test_helpers.py b/lib/lp/scripts/tests/test_helpers.py
303index 8dda0d5..b2e442d 100644
304--- a/lib/lp/scripts/tests/test_helpers.py
305+++ b/lib/lp/scripts/tests/test_helpers.py
306@@ -3,6 +3,8 @@
307
308 """Test the helpers."""
309
310+from __future__ import absolute_import, print_function, unicode_literals
311+
312 __metaclass__ = type
313
314 from testtools.testcase import ExpectedException
315diff --git a/lib/lp/scripts/tests/test_runlaunchpad.py b/lib/lp/scripts/tests/test_runlaunchpad.py
316index cbeb980..461a3e5 100644
317--- a/lib/lp/scripts/tests/test_runlaunchpad.py
318+++ b/lib/lp/scripts/tests/test_runlaunchpad.py
319@@ -3,6 +3,8 @@
320
321 """Tests for runlaunchpad.py"""
322
323+from __future__ import absolute_import, print_function, unicode_literals
324+
325 __metaclass__ = type
326 __all__ = [
327 'CommandLineArgumentProcessing',
328diff --git a/lib/lp/scripts/tests/test_scriptmonitor.py b/lib/lp/scripts/tests/test_scriptmonitor.py
329index 95e8b43..058ee97 100644
330--- a/lib/lp/scripts/tests/test_scriptmonitor.py
331+++ b/lib/lp/scripts/tests/test_scriptmonitor.py
332@@ -3,6 +3,8 @@
333
334 """Test scriptmonitor.py."""
335
336+from __future__ import absolute_import, print_function, unicode_literals
337+
338 __metaclass__ = type
339
340 from unittest import TestCase
341diff --git a/lib/lp/scripts/tests/test_sphinxdocs.py b/lib/lp/scripts/tests/test_sphinxdocs.py
342index 194da50..b2f355f 100644
343--- a/lib/lp/scripts/tests/test_sphinxdocs.py
344+++ b/lib/lp/scripts/tests/test_sphinxdocs.py
345@@ -3,6 +3,8 @@
346
347 """Tests for our Sphinx documentation."""
348
349+from __future__ import absolute_import, print_function, unicode_literals
350+
351 __metaclass__ = type
352
353 import os
354diff --git a/lib/lp/scripts/utilities/importpedant.py b/lib/lp/scripts/utilities/importpedant.py
355index afb9fe8..7a56898 100644
356--- a/lib/lp/scripts/utilities/importpedant.py
357+++ b/lib/lp/scripts/utilities/importpedant.py
358@@ -1,6 +1,8 @@
359 # Copyright 2009-2016 Canonical Ltd. This software is licensed under the
360 # GNU Affero General Public License version 3 (see the file LICENSE).
361
362+from __future__ import absolute_import, print_function, unicode_literals
363+
364 import __builtin__
365 import atexit
366 import itertools
367@@ -254,8 +256,8 @@ def import_pedant(name, globals={}, locals={}, fromlist=[], level=-1):
368
369 def report_naughty_imports():
370 if naughty_imports:
371- print
372- print '** %d import policy violations **' % len(naughty_imports)
373+ print()
374+ print('** %d import policy violations **' % len(naughty_imports))
375
376 database_violations = []
377 fromstar_violations = []
378@@ -269,38 +271,38 @@ def report_naughty_imports():
379 sorting_map[error.__class__].append(error)
380
381 if database_violations:
382- print
383- print "There were %s database import violations." % (
384- len(database_violations))
385+ print()
386+ print("There were %s database import violations." % (
387+ len(database_violations)))
388 sorted_violations = sorted(
389 database_violations,
390 key=attrsgetter('name', 'import_into'))
391
392 for name, sequence in itertools.groupby(
393 sorted_violations, attrgetter('name')):
394- print "You should not import %s into:" % name
395+ print("You should not import %s into:" % name)
396 for import_into, unused_duplicates_seq in itertools.groupby(
397 sequence, attrgetter('import_into')):
398 # Show first occurrence only, to avoid duplicates.
399- print " ", import_into
400+ print(" ", import_into)
401
402 if fromstar_violations:
403- print
404- print "There were %s imports 'from *' without an __all__." % (
405- len(fromstar_violations))
406+ print()
407+ print("There were %s imports 'from *' without an __all__." % (
408+ len(fromstar_violations)))
409 sorted_violations = sorted(
410 fromstar_violations,
411 key=attrsgetter('import_into', 'name'))
412
413 for import_into, sequence in itertools.groupby(
414 sorted_violations, attrgetter('import_into')):
415- print "You should not import * into %s from" % import_into
416+ print("You should not import * into %s from" % import_into)
417 for error in sequence:
418- print " ", error.name
419+ print(" ", error.name)
420
421 if notinall_violations:
422- print
423- print (
424+ print()
425+ print(
426 "There were %s imports of names not appearing in the __all__."
427 % len(notinall_violations))
428 sorted_violations = sorted(
429@@ -309,11 +311,11 @@ def report_naughty_imports():
430
431 for (name, attrname), sequence in itertools.groupby(
432 sorted_violations, attrsgetter('name', 'attrname')):
433- print "You should not import %s from %s:" % (attrname, name)
434+ print("You should not import %s from %s:" % (attrname, name))
435 import_intos = sorted(
436 set([error.import_into for error in sequence]))
437 for import_into in import_intos:
438- print " ", import_into
439+ print(" ", import_into)
440
441
442 def install_import_pedant():
443diff --git a/lib/lp/scripts/utilities/killservice.py b/lib/lp/scripts/utilities/killservice.py
444index bc7caef..ef91f58 100755
445--- a/lib/lp/scripts/utilities/killservice.py
446+++ b/lib/lp/scripts/utilities/killservice.py
447@@ -3,7 +3,8 @@
448 # Copyright 2009-2018 Canonical Ltd. This software is licensed under the
449 # GNU Affero General Public License version 3 (see the file LICENSE).
450
451-# This module uses relative imports.
452+from __future__ import absolute_import, print_function, unicode_literals
453+
454 __metaclass__ = type
455
456 import logging
457diff --git a/lib/lp/scripts/utilities/settingsauditor.py b/lib/lp/scripts/utilities/settingsauditor.py
458index 2637aa0..32794eb 100644
459--- a/lib/lp/scripts/utilities/settingsauditor.py
460+++ b/lib/lp/scripts/utilities/settingsauditor.py
461@@ -3,6 +3,8 @@
462
463 """Contains the seting auditor used to clean up security.cfg."""
464
465+from __future__ import absolute_import, print_function, unicode_literals
466+
467 __metaclass__ = type
468
469 __all__ = [
470diff --git a/lib/lp/scripts/utilities/test.py b/lib/lp/scripts/utilities/test.py
471index 1899105..208c764 100755
472--- a/lib/lp/scripts/utilities/test.py
473+++ b/lib/lp/scripts/utilities/test.py
474@@ -13,6 +13,8 @@
475 ##############################################################################
476 """Test script."""
477
478+from __future__ import absolute_import, print_function, unicode_literals
479+
480 import argparse
481 import doctest
482 import os
483diff --git a/lib/lp/scripts/utilities/tests/test_audit_security_settings.py b/lib/lp/scripts/utilities/tests/test_audit_security_settings.py
484index 3a0e13d..87a5388 100644
485--- a/lib/lp/scripts/utilities/tests/test_audit_security_settings.py
486+++ b/lib/lp/scripts/utilities/tests/test_audit_security_settings.py
487@@ -3,6 +3,8 @@
488
489 """Tests the security.cfg auditor."""
490
491+from __future__ import absolute_import, print_function, unicode_literals
492+
493 __metaclass__ = type
494
495 from lp.scripts.utilities.settingsauditor import SettingsAuditor
496diff --git a/lib/lp/scripts/utilities/tests/test_shhh.py b/lib/lp/scripts/utilities/tests/test_shhh.py
497index 4908e22..c00e2f8 100644
498--- a/lib/lp/scripts/utilities/tests/test_shhh.py
499+++ b/lib/lp/scripts/utilities/tests/test_shhh.py
500@@ -1,6 +1,8 @@
501 # Copyright 2009 Canonical Ltd. This software is licensed under the
502 # GNU Affero General Public License version 3 (see the file LICENSE).
503
504+from __future__ import absolute_import, print_function, unicode_literals
505+
506 __metaclass__ = type
507
508 from doctest import DocTestSuite

Subscribers

People subscribed via source and target branches

to status/vote changes: