← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:services-scripts-print-function into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:services-scripts-print-function into launchpad:master.

Commit message:
Port lp.services.scripts to print_function

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/392045
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:services-scripts-print-function into launchpad:master.
diff --git a/lib/lp/services/scripts/__init__.py b/lib/lp/services/scripts/__init__.py
index d4a362d..42a6f2a 100644
--- a/lib/lp/services/scripts/__init__.py
+++ b/lib/lp/services/scripts/__init__.py
@@ -151,7 +151,7 @@ def db_options(parser):
     >>> parser = OptionParser()
     >>> db_options(parser)
     >>> options, args = parser.parse_args([])
-    >>> print options.dbuser
+    >>> print(options.dbuser)
     None
     """
     conn_string = ConnectionString(config.database.rw_main_master)
diff --git a/lib/lp/services/scripts/doc/launchpad-scripts.txt b/lib/lp/services/scripts/doc/launchpad-scripts.txt
index d217754..f5765a0 100644
--- a/lib/lp/services/scripts/doc/launchpad-scripts.txt
+++ b/lib/lp/services/scripts/doc/launchpad-scripts.txt
@@ -25,7 +25,7 @@ LaunchpadCronScript) also log warnings and and errors as OOPS reports.
     ...     [sys.executable, cronscript_crash_path, '-vq'],
     ...     stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
     ...     stdin=subprocess.PIPE)
-    >>> print p.communicate()[0]
+    >>> print(p.communicate()[0])
     INFO    Creating lockfile: ...
     WARNING This is a warning
     INFO    None
diff --git a/lib/lp/services/scripts/doc/script-monitoring.txt b/lib/lp/services/scripts/doc/script-monitoring.txt
index 8c1ffac..9e22745 100644
--- a/lib/lp/services/scripts/doc/script-monitoring.txt
+++ b/lib/lp/services/scripts/doc/script-monitoring.txt
@@ -41,13 +41,13 @@ IScriptActivitySet.recordSuccess():
 The activity object records the script name, the host name it ran on
 and the start and end timestamps:
 
-    >>> print activity.name
+    >>> print(activity.name)
     script-name
-    >>> print activity.hostname
+    >>> print(activity.hostname)
     script-host
-    >>> print activity.date_started
+    >>> print(activity.date_started)
     2007-02-01 10:00:00+00:00
-    >>> print activity.date_completed
+    >>> print(activity.date_completed)
     2007-02-01 10:01:00+00:00
 
 We can also query for the last activity for a particular script, which
@@ -55,14 +55,14 @@ will match the activity we just created:
 
     >>> activity = getUtility(IScriptActivitySet).getLastActivity(
     ...     'script-name')
-    >>> print activity.date_started
+    >>> print(activity.date_started)
     2007-02-01 10:00:00+00:00
 
 If no activity has occurred for a script, getLastActivity() returns
 None:
 
-    >>> print getUtility(IScriptActivitySet).getLastActivity(
-    ...     'no-such-script')
+    >>> print(getUtility(IScriptActivitySet).getLastActivity(
+    ...     'no-such-script'))
     None
 
 If the hostname parameter is omitted, it defaults to the host the
@@ -116,12 +116,12 @@ We'll now run this script, telling it to fail:
 
 The process failed:
 
-    >>> print proc.returncode
+    >>> print(proc.returncode)
     1
 
 And no activity got recorded:
 
-    >>> print getUtility(IScriptActivitySet).getLastActivity('test-script')
+    >>> print(getUtility(IScriptActivitySet).getLastActivity('test-script'))
     None
 
 If we run it such that it succeeds, we will get an activity record:
@@ -132,13 +132,13 @@ If we run it such that it succeeds, we will get an activity record:
     >>> (out, err) = proc.communicate()
     >>> transaction.abort()
 
-    >>> print proc.returncode
+    >>> print(proc.returncode)
     0
     >>> activity = getUtility(IScriptActivitySet).getLastActivity(
     ...     'test-script')
     >>> activity is not None
     True
-    >>> print activity.name
+    >>> print(activity.name)
     test-script
     >>> activity.hostname == socket.gethostname()
     True
diff --git a/lib/lp/services/scripts/doc/scripts-and-zcml.txt b/lib/lp/services/scripts/doc/scripts-and-zcml.txt
index 48b6cb5..ab16030 100644
--- a/lib/lp/services/scripts/doc/scripts-and-zcml.txt
+++ b/lib/lp/services/scripts/doc/scripts-and-zcml.txt
@@ -13,12 +13,14 @@ to demonstrate this:
     >>> from textwrap import dedent
     >>> script_file = tempfile.NamedTemporaryFile()
     >>> script_file.write(dedent("""\
+    ...     from __future__ import absolute_import, print_function
+    ...
     ...     from lp.services.scripts import execute_zcml_for_scripts
     ...     from lp.registry.interfaces.person import IPersonSet
     ...     from zope.component import getUtility
     ... 
     ...     execute_zcml_for_scripts()
-    ...     print getUtility(IPersonSet).get(1).displayname
+    ...     print(getUtility(IPersonSet).get(1).displayname)
     ...     """))
     >>> script_file.flush()
 
@@ -31,10 +33,10 @@ Run the script (making sure it uses the testrunner configuration).
 
 Check that we get the expected output.
 
-    >>> print proc.stdout.read()
+    >>> print(proc.stdout.read())
     Mark Shuttleworth
 
-    >>> print proc.wait()
+    >>> print(proc.wait())
     0
 
 Remove the temporary file.
diff --git a/lib/lp/services/scripts/tests/loglevels.py b/lib/lp/services/scripts/tests/loglevels.py
index babe309..5e760f6 100644
--- a/lib/lp/services/scripts/tests/loglevels.py
+++ b/lib/lp/services/scripts/tests/loglevels.py
@@ -6,6 +6,8 @@
 Used by test_logger.txt.
 """
 
+from __future__ import absolute_import, print_function
+
 __metaclass__ = type
 __all__ = []
 
@@ -31,7 +33,7 @@ logger_options(parser)
 options, args = parser.parse_args()
 
 if len(args) > 0:
-    print "Args: %s" % repr(args)
+    print("Args: %s" % repr(args))
 
 log = logger(options, 'loglevels')
 
diff --git a/lib/lp/services/scripts/tests/test_doc.py b/lib/lp/services/scripts/tests/test_doc.py
index 98ade43..f8756dc 100644
--- a/lib/lp/services/scripts/tests/test_doc.py
+++ b/lib/lp/services/scripts/tests/test_doc.py
@@ -14,6 +14,7 @@ from lp.testing.layers import (
     )
 from lp.testing.systemdocs import (
     LayeredDocFileSuite,
+    setGlobs,
     setUp,
     tearDown,
     )
@@ -24,15 +25,17 @@ here = os.path.dirname(os.path.realpath(__file__))
 special = {
     'script-monitoring.txt': LayeredDocFileSuite(
             '../doc/script-monitoring.txt',
-            setUp=setUp, tearDown=tearDown,
+            setUp=lambda test: setUp(test, future=True), tearDown=tearDown,
             layer=LaunchpadZopelessLayer,
             ),
     'launchpad-scripts.txt': LayeredDocFileSuite(
             '../doc/launchpad-scripts.txt',
+            setUp=lambda test: setGlobs(test, future=True),
             layer=DatabaseLayer,
             ),
 }
 
 
 def test_suite():
-    return build_test_suite(here, special)
+    return build_test_suite(
+        here, special, setUp=lambda test: setGlobs(test, future=True))
diff --git a/lib/lp/services/scripts/tests/test_logger.py b/lib/lp/services/scripts/tests/test_logger.py
index 95bd9d9..9b9b2c8 100644
--- a/lib/lp/services/scripts/tests/test_logger.py
+++ b/lib/lp/services/scripts/tests/test_logger.py
@@ -16,7 +16,10 @@ from lp.services.scripts.logger import LaunchpadFormatter
 from lp.services.utils import traceback_info
 from lp.testing import TestCase
 from lp.testing.layers import BaseLayer
-from lp.testing.systemdocs import LayeredDocFileSuite
+from lp.testing.systemdocs import (
+    LayeredDocFileSuite,
+    setGlobs,
+    )
 
 
 DOCTEST_FLAGS = (
@@ -54,7 +57,8 @@ def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(
         LayeredDocFileSuite(
-            'test_logger.txt', layer=BaseLayer))
+            'test_logger.txt',
+            setUp=lambda test: setGlobs(test, future=True), layer=BaseLayer))
     suite.addTest(
         unittest.TestLoader().loadTestsFromName(__name__))
     return suite
diff --git a/lib/lp/services/scripts/tests/test_logger.txt b/lib/lp/services/scripts/tests/test_logger.txt
index 051ce4e..05cb8aa 100644
--- a/lib/lp/services/scripts/tests/test_logger.txt
+++ b/lib/lp/services/scripts/tests/test_logger.txt
@@ -16,7 +16,7 @@ by our logging handler.
     ...         stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kw)
     ...     out, err = proc.communicate()
     ...     assert out == "", "Output to stdout"
-    ...     print err
+    ...     print(err)
 
 
 The default is to output INFO messages and above.
@@ -96,7 +96,7 @@ FATAL is an alias for CRITICAL, and DEBUG1 is an alias for DEBUG.
     ...     loglevels.DEBUG7, loglevels.DEBUG8, loglevels.DEBUG9]
     >>> import logging
     >>> for level in levels:
-    ...     print "%2d %s" % (level, logging.getLevelName(level))
+    ...     print("%2d %s" % (level, logging.getLevelName(level)))
     50 CRITICAL
     50 CRITICAL
     40 ERROR