launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24191
[Merge] ~cjwatson/launchpad:scripts-future-imports into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:scripts-future-imports into launchpad:master with ~cjwatson/launchpad:scripts-utilities-js-future-imports as a prerequisite.
Commit message:
Convert lp.scripts to preferred __future__ imports
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/377137
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:scripts-future-imports into launchpad:master.
diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
index b6b5f27..6f6ad6b 100644
--- a/lib/lp/scripts/garbo.py
+++ b/lib/lp/scripts/garbo.py
@@ -3,6 +3,8 @@
"""Database garbage collection."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
'DailyDatabaseGarbageCollector',
@@ -456,7 +458,7 @@ class VoucherRedeemer(TunableLoop):
def _pending_subscriptions(self):
return self.store.find(
CommercialSubscription,
- Like(CommercialSubscription.sales_system_id, u'pending-%')
+ Like(CommercialSubscription.sales_system_id, 'pending-%')
)
def isDone(self):
diff --git a/lib/lp/scripts/harness.py b/lib/lp/scripts/harness.py
index 45c23c7..7bfe67e 100644
--- a/lib/lp/scripts/harness.py
+++ b/lib/lp/scripts/harness.py
@@ -9,6 +9,8 @@ launchpad_dev or the database specified on the command line.
One uses Python, the other iPython.
"""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = ['python', 'ipython']
diff --git a/lib/lp/scripts/helpers.py b/lib/lp/scripts/helpers.py
index a534c6c..99922c3 100644
--- a/lib/lp/scripts/helpers.py
+++ b/lib/lp/scripts/helpers.py
@@ -3,6 +3,8 @@
"""Helpers for command line tools."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = ["LPOptionParser", "TransactionFreeOperation", ]
diff --git a/lib/lp/scripts/runlaunchpad.py b/lib/lp/scripts/runlaunchpad.py
index b66e26f..9fc5add 100644
--- a/lib/lp/scripts/runlaunchpad.py
+++ b/lib/lp/scripts/runlaunchpad.py
@@ -1,6 +1,8 @@
# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = ['start_launchpad']
@@ -377,9 +379,9 @@ def start_testapp(argv=list(sys.argv)):
teardowns.append(LayerProcessController.stopSMTPServer)
if interactive_tests:
root_url = config.appserver_root_url()
- print '*' * 70
- print 'In a few seconds, go to ' + root_url + '/+yuitest'
- print '*' * 70
+ print('*' * 70)
+ print('In a few seconds, go to ' + root_url + '/+yuitest')
+ print('*' * 70)
try:
start_launchpad(argv, setup)
finally:
@@ -422,19 +424,19 @@ def start_launchpad(argv=list(sys.argv), setup=None):
except KeyboardInterrupt:
pass
except Exception as e:
- print >> sys.stderr, "stopping services on exception %r" % e
+ print("stopping services on exception %r" % e, file=sys.stderr)
for service in services:
- print >> sys.stderr, service, "fixture details:"
+ print(service, "fixture details:", file=sys.stderr)
# There may be no details on some services if they haven't been
# initialized yet.
if getattr(service, '_details', None) is None:
- print >> sys.stderr, "(not ready yet?)"
+ print("(not ready yet?)", file=sys.stderr)
continue
details_str = _details_to_str(service.getDetails())
if details_str:
- print >> sys.stderr, details_str
+ print(details_str, file=sys.stderr)
else:
- print >> sys.stderr, "(no details present)"
+ print("(no details present)", file=sys.stderr)
raise
diff --git a/lib/lp/scripts/scriptmonitor.py b/lib/lp/scripts/scriptmonitor.py
index 72dad3e..57b1426 100644
--- a/lib/lp/scripts/scriptmonitor.py
+++ b/lib/lp/scripts/scriptmonitor.py
@@ -3,6 +3,8 @@
"""Monitor whether scripts have run between specified time periods."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = ['check_script']
diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
index 329b8fc..e0cb87e 100644
--- a/lib/lp/scripts/tests/test_garbo.py
+++ b/lib/lp/scripts/tests/test_garbo.py
@@ -3,6 +3,8 @@
"""Test the database garbage collector."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = []
@@ -274,12 +276,12 @@ class TestSessionPruner(TestCase):
yesterday = recent - timedelta(days=1)
ancient = recent - timedelta(days=61)
- self.make_session(u'recent_auth', recent, 'auth1')
- self.make_session(u'recent_unauth', recent, False)
- self.make_session(u'yesterday_auth', yesterday, 'auth2')
- self.make_session(u'yesterday_unauth', yesterday, False)
- self.make_session(u'ancient_auth', ancient, 'auth3')
- self.make_session(u'ancient_unauth', ancient, False)
+ self.make_session('recent_auth', recent, b'auth1')
+ self.make_session('recent_unauth', recent, False)
+ self.make_session('yesterday_auth', yesterday, b'auth2')
+ self.make_session('yesterday_unauth', yesterday, False)
+ self.make_session('ancient_auth', ancient, b'auth3')
+ self.make_session('ancient_unauth', ancient, False)
self.log = logging.getLogger('garbo')
@@ -293,16 +295,16 @@ class TestSessionPruner(TestCase):
# Add login time information.
session_pkg_data = SessionPkgData()
session_pkg_data.client_id = client_id
- session_pkg_data.product_id = u'launchpad.authenticateduser'
- session_pkg_data.key = u'logintime'
- session_pkg_data.pickle = 'value is ignored'
+ session_pkg_data.product_id = 'launchpad.authenticateduser'
+ session_pkg_data.key = 'logintime'
+ session_pkg_data.pickle = b'value is ignored'
IMasterStore(SessionPkgData).add(session_pkg_data)
# Add authenticated as information.
session_pkg_data = SessionPkgData()
session_pkg_data.client_id = client_id
- session_pkg_data.product_id = u'launchpad.authenticateduser'
- session_pkg_data.key = u'accountid'
+ session_pkg_data.product_id = 'launchpad.authenticateduser'
+ session_pkg_data.key = 'accountid'
# Normally Account.id, but the session pruning works
# at the SQL level and doesn't unpickle anything.
session_pkg_data.pickle = authenticated
@@ -323,12 +325,12 @@ class TestSessionPruner(TestCase):
pruner.cleanUp()
expected_sessions = set([
- u'recent_auth',
- u'recent_unauth',
- u'yesterday_auth',
- u'yesterday_unauth',
- # u'ancient_auth',
- # u'ancient_unauth',
+ 'recent_auth',
+ 'recent_unauth',
+ 'yesterday_auth',
+ 'yesterday_unauth',
+ # 'ancient_auth',
+ # 'ancient_unauth',
])
found_sessions = set(
@@ -346,12 +348,12 @@ class TestSessionPruner(TestCase):
pruner.cleanUp()
expected_sessions = set([
- u'recent_auth',
- u'recent_unauth',
- u'yesterday_auth',
- # u'yesterday_unauth',
- u'ancient_auth',
- # u'ancient_unauth',
+ 'recent_auth',
+ 'recent_unauth',
+ 'yesterday_auth',
+ # 'yesterday_unauth',
+ 'ancient_auth',
+ # 'ancient_unauth',
])
found_sessions = set(
@@ -363,12 +365,12 @@ class TestSessionPruner(TestCase):
# None of the sessions created in setUp() are duplicates, so
# they will all survive the pruning.
expected_sessions = set([
- u'recent_auth',
- u'recent_unauth',
- u'yesterday_auth',
- u'yesterday_unauth',
- u'ancient_auth',
- u'ancient_unauth',
+ 'recent_auth',
+ 'recent_unauth',
+ 'yesterday_auth',
+ 'yesterday_unauth',
+ 'ancient_auth',
+ 'ancient_unauth',
])
now = datetime.now(UTC)
@@ -378,17 +380,17 @@ class TestSessionPruner(TestCase):
# most recent 'old dupe 1'.
for count in range(1, 10):
self.make_session(
- u'old dupe %d' % count,
+ 'old dupe %d' % count,
now - timedelta(days=2, seconds=count),
- 'old dupe')
+ b'old dupe')
for count in range(1, 7):
- expected_sessions.add(u'old dupe %d' % count)
+ expected_sessions.add('old dupe %d' % count)
# Make some other duplicate logins less than an hour old.
# All of these will be kept.
for count in range(1, 10):
- self.make_session(u'new dupe %d' % count, now, 'new dupe')
- expected_sessions.add(u'new dupe %d' % count)
+ self.make_session('new dupe %d' % count, now, b'new dupe')
+ expected_sessions.add('new dupe %d' % count)
chunk_size = 2
pruner = DuplicateSessionPruner(self.log)
@@ -483,8 +485,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
self.assertEqual(store.find(OpenIDConsumerNonce).count(), 0)
for timestamp in timestamps:
- store.add(OpenIDConsumerNonce(
- u'http://server/', timestamp, u'aa'))
+ store.add(OpenIDConsumerNonce('http://server/', timestamp, 'aa'))
transaction.commit()
# Make sure we have 4 nonces now.
@@ -1171,7 +1172,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
# There should now be 0 pending vouchers in Launchpad.
num_rows = IMasterStore(CommercialSubscription).find(
CommercialSubscription,
- Like(CommercialSubscription.sales_system_id, u'pending-%')
+ Like(CommercialSubscription.sales_system_id, 'pending-%')
).count()
self.assertThat(num_rows, Equals(0))
# Salesforce should also now have redeemed the voucher.
@@ -1268,7 +1269,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
naked_bug = removeSecurityProxy(bug)
naked_bug.heat_last_updated = old_update
IMasterStore(FeatureFlag).add(FeatureFlag(
- u'default', 0, u'bugs.heat_updates.cutoff',
+ 'default', 0, 'bugs.heat_updates.cutoff',
cutoff.isoformat().decode('ascii')))
transaction.commit()
self.assertEqual(old_update, naked_bug.heat_last_updated)
@@ -1452,7 +1453,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
self.assertIsNotNone(
store.execute(
'SELECT * FROM GarboJobState WHERE name=?',
- params=[u'PopulateLatestPersonSourcePackageReleaseCache']
+ params=['PopulateLatestPersonSourcePackageReleaseCache']
).get_one())
def _assert_releases_by_creator(creator, sprs):
@@ -1527,7 +1528,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
# test LiveFS file as a base image for its DAS.
now = datetime.now(UTC)
switch_dbuser('testadmin')
- self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: u'on'}))
+ self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: 'on'}))
store = IMasterStore(LiveFSFile)
initial_count = store.find(LiveFSFile).count()
@@ -1596,7 +1597,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
# An old LiveFS binary file is pruned even if some other base image
# exists.
switch_dbuser('testadmin')
- self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: u'on'}))
+ self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: 'on'}))
store = IMasterStore(LiveFSFile)
other_build = self.factory.makeLiveFSBuild(
status=BuildStatus.FULLYBUILT, duration=timedelta(minutes=10))
diff --git a/lib/lp/scripts/tests/test_helpers.py b/lib/lp/scripts/tests/test_helpers.py
index 8dda0d5..b2e442d 100644
--- a/lib/lp/scripts/tests/test_helpers.py
+++ b/lib/lp/scripts/tests/test_helpers.py
@@ -3,6 +3,8 @@
"""Test the helpers."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from testtools.testcase import ExpectedException
diff --git a/lib/lp/scripts/tests/test_runlaunchpad.py b/lib/lp/scripts/tests/test_runlaunchpad.py
index cbeb980..461a3e5 100644
--- a/lib/lp/scripts/tests/test_runlaunchpad.py
+++ b/lib/lp/scripts/tests/test_runlaunchpad.py
@@ -3,6 +3,8 @@
"""Tests for runlaunchpad.py"""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
'CommandLineArgumentProcessing',
diff --git a/lib/lp/scripts/tests/test_scriptmonitor.py b/lib/lp/scripts/tests/test_scriptmonitor.py
index 95e8b43..058ee97 100644
--- a/lib/lp/scripts/tests/test_scriptmonitor.py
+++ b/lib/lp/scripts/tests/test_scriptmonitor.py
@@ -3,6 +3,8 @@
"""Test scriptmonitor.py."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from unittest import TestCase
diff --git a/lib/lp/scripts/tests/test_sphinxdocs.py b/lib/lp/scripts/tests/test_sphinxdocs.py
index 194da50..b2f355f 100644
--- a/lib/lp/scripts/tests/test_sphinxdocs.py
+++ b/lib/lp/scripts/tests/test_sphinxdocs.py
@@ -3,6 +3,8 @@
"""Tests for our Sphinx documentation."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
import os
diff --git a/lib/lp/scripts/utilities/importpedant.py b/lib/lp/scripts/utilities/importpedant.py
index afb9fe8..7a56898 100644
--- a/lib/lp/scripts/utilities/importpedant.py
+++ b/lib/lp/scripts/utilities/importpedant.py
@@ -1,6 +1,8 @@
# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+from __future__ import absolute_import, print_function, unicode_literals
+
import __builtin__
import atexit
import itertools
@@ -254,8 +256,8 @@ def import_pedant(name, globals={}, locals={}, fromlist=[], level=-1):
def report_naughty_imports():
if naughty_imports:
- print
- print '** %d import policy violations **' % len(naughty_imports)
+ print()
+ print('** %d import policy violations **' % len(naughty_imports))
database_violations = []
fromstar_violations = []
@@ -269,38 +271,38 @@ def report_naughty_imports():
sorting_map[error.__class__].append(error)
if database_violations:
- print
- print "There were %s database import violations." % (
- len(database_violations))
+ print()
+ print("There were %s database import violations." % (
+ len(database_violations)))
sorted_violations = sorted(
database_violations,
key=attrsgetter('name', 'import_into'))
for name, sequence in itertools.groupby(
sorted_violations, attrgetter('name')):
- print "You should not import %s into:" % name
+ print("You should not import %s into:" % name)
for import_into, unused_duplicates_seq in itertools.groupby(
sequence, attrgetter('import_into')):
# Show first occurrence only, to avoid duplicates.
- print " ", import_into
+ print(" ", import_into)
if fromstar_violations:
- print
- print "There were %s imports 'from *' without an __all__." % (
- len(fromstar_violations))
+ print()
+ print("There were %s imports 'from *' without an __all__." % (
+ len(fromstar_violations)))
sorted_violations = sorted(
fromstar_violations,
key=attrsgetter('import_into', 'name'))
for import_into, sequence in itertools.groupby(
sorted_violations, attrgetter('import_into')):
- print "You should not import * into %s from" % import_into
+ print("You should not import * into %s from" % import_into)
for error in sequence:
- print " ", error.name
+ print(" ", error.name)
if notinall_violations:
- print
- print (
+ print()
+ print(
"There were %s imports of names not appearing in the __all__."
% len(notinall_violations))
sorted_violations = sorted(
@@ -309,11 +311,11 @@ def report_naughty_imports():
for (name, attrname), sequence in itertools.groupby(
sorted_violations, attrsgetter('name', 'attrname')):
- print "You should not import %s from %s:" % (attrname, name)
+ print("You should not import %s from %s:" % (attrname, name))
import_intos = sorted(
set([error.import_into for error in sequence]))
for import_into in import_intos:
- print " ", import_into
+ print(" ", import_into)
def install_import_pedant():
diff --git a/lib/lp/scripts/utilities/killservice.py b/lib/lp/scripts/utilities/killservice.py
index bc7caef..ef91f58 100755
--- a/lib/lp/scripts/utilities/killservice.py
+++ b/lib/lp/scripts/utilities/killservice.py
@@ -3,7 +3,8 @@
# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
-# This module uses relative imports.
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
import logging
diff --git a/lib/lp/scripts/utilities/settingsauditor.py b/lib/lp/scripts/utilities/settingsauditor.py
index 2637aa0..32794eb 100644
--- a/lib/lp/scripts/utilities/settingsauditor.py
+++ b/lib/lp/scripts/utilities/settingsauditor.py
@@ -3,6 +3,8 @@
"""Contains the seting auditor used to clean up security.cfg."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
__all__ = [
diff --git a/lib/lp/scripts/utilities/test.py b/lib/lp/scripts/utilities/test.py
index 1899105..208c764 100755
--- a/lib/lp/scripts/utilities/test.py
+++ b/lib/lp/scripts/utilities/test.py
@@ -13,6 +13,8 @@
##############################################################################
"""Test script."""
+from __future__ import absolute_import, print_function, unicode_literals
+
import argparse
import doctest
import os
diff --git a/lib/lp/scripts/utilities/tests/test_audit_security_settings.py b/lib/lp/scripts/utilities/tests/test_audit_security_settings.py
index 3a0e13d..87a5388 100644
--- a/lib/lp/scripts/utilities/tests/test_audit_security_settings.py
+++ b/lib/lp/scripts/utilities/tests/test_audit_security_settings.py
@@ -3,6 +3,8 @@
"""Tests the security.cfg auditor."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from lp.scripts.utilities.settingsauditor import SettingsAuditor
diff --git a/lib/lp/scripts/utilities/tests/test_shhh.py b/lib/lp/scripts/utilities/tests/test_shhh.py
index 4908e22..c00e2f8 100644
--- a/lib/lp/scripts/utilities/tests/test_shhh.py
+++ b/lib/lp/scripts/utilities/tests/test_shhh.py
@@ -1,6 +1,8 @@
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from doctest import DocTestSuite