← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/no-py25 into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/no-py25 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/no-py25/+merge/112789

Lots of people have left notes over the years of code to be removed once Launchpad no longer requires Python 2.4 or 2.5.  Since we're running entirely on 2.6 now and should soon be switching to 2.7, it's about time to clean some of this up.
-- 
https://code.launchpad.net/~cjwatson/launchpad/no-py25/+merge/112789
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/no-py25 into lp:launchpad.
=== modified file 'lib/lp/code/scripts/tests/test_request_daily_builds.py'
--- lib/lp/code/scripts/tests/test_request_daily_builds.py	2012-01-01 02:58:52 +0000
+++ lib/lp/code/scripts/tests/test_request_daily_builds.py	2012-06-29 14:42:40 +0000
@@ -1,6 +1,4 @@
-#! /usr/bin/python2.5
-#
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test the request_daily_builds script"""

=== modified file 'lib/lp/code/scripts/tests/test_upgrade_branches.py'
--- lib/lp/code/scripts/tests/test_upgrade_branches.py	2012-01-01 02:58:52 +0000
+++ lib/lp/code/scripts/tests/test_upgrade_branches.py	2012-06-29 14:42:40 +0000
@@ -1,6 +1,4 @@
-#! /usr/bin/python2.4
-#
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test the upgrade_branches script."""

=== modified file 'lib/lp/registry/doc/standing.txt'
--- lib/lp/registry/doc/standing.txt	2012-01-20 15:42:44 +0000
+++ lib/lp/registry/doc/standing.txt	2012-06-29 14:42:40 +0000
@@ -46,10 +46,9 @@
     ...     held_message = mailing_list.holdMessage(message)
     ...     return held_message
 
-    # A helper for the common case.  IWBNI we had Python 2.5 because
-    # then we could just use functools.partial().
-    >>> def lifeless_post(to_team_name):
-    ...     return post_message('robertc@xxxxxxxxxxxxxxxxx', to_team_name)
+    # A helper for the common case.
+    >>> from functools import partial
+    >>> lifeless_post = partial(post_message, 'robertc@xxxxxxxxxxxxxxxxx')
 
     >>> from lp.registry.scripts.standing import (
     ...     UpdatePersonalStanding)

=== modified file 'lib/lp/registry/model/productrelease.py'
--- lib/lp/registry/model/productrelease.py	2011-12-30 06:14:56 +0000
+++ lib/lp/registry/model/productrelease.py	2012-06-29 14:42:40 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 # pylint: disable-msg=E0611,W0212
@@ -11,6 +11,7 @@
     'productrelease_to_milestone',
     ]
 
+import os
 from StringIO import StringIO
 
 from sqlobject import (
@@ -53,9 +54,6 @@
     )
 
 
-SEEK_END = 2                    # Python2.4 has no definition for SEEK_END.
-
-
 class ProductRelease(SQLBase):
     """A release of a product."""
     implements(IProductRelease)
@@ -154,7 +152,7 @@
                 "file_or_data is not an expected type")
             file_obj = file_or_data
             start = file_obj.tell()
-            file_obj.seek(0, SEEK_END)
+            file_obj.seek(0, os.SEEK_END)
             file_size = file_obj.tell()
             file_obj.seek(start)
         return file_obj, file_size

=== modified file 'lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt'
--- lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt	2012-04-17 16:05:54 +0000
+++ lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt	2012-06-29 14:42:40 +0000
@@ -382,12 +382,8 @@
     >>> import os
     >>> def read_file(filename):
     ...     path = os.path.join(os.path.dirname(__file__), filename)
-    ...     file_object = open(path)
-    ...     # Change this to a with-statement when we switch to Python 2.5.
-    ...     try:
+    ...     with open(path) as file_object:
     ...         return file_object.read()
-    ...     finally:
-    ...         file_object.close()
 
 
 Code of Conduct registration problems

=== modified file 'lib/lp/services/gpg/handler.py'
--- lib/lp/services/gpg/handler.py	2012-03-26 07:14:35 +0000
+++ lib/lp/services/gpg/handler.py	2012-06-29 14:42:40 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -187,14 +187,7 @@
         try:
             signatures = ctx.verify(*args)
         except gpgme.GpgmeError, e:
-            # XXX: 2010-04-26, Salgado, bug=570244: This hack is needed
-            # for python2.5 compatibility. We should remove it when we no
-            # longer need to run on python2.5.
-            if hasattr(e, 'strerror'):
-                msg = e.strerror
-            else:
-                msg = e.message
-            error = GPGVerificationError(msg)
+            error = GPGVerificationError(e.strerror)
             for attr in ("args", "code", "signatures", "source"):
                 if hasattr(e, attr):
                     value = getattr(e, attr)

=== modified file 'lib/lp/services/librarian/client.py'
--- lib/lp/services/librarian/client.py	2011-12-30 06:14:56 +0000
+++ lib/lp/services/librarian/client.py	2012-06-29 14:42:40 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -189,7 +189,7 @@
 
             # Read in and upload the file 64kb at a time, by using the two-arg
             # form of iter (see
-            # /usr/share/doc/python2.4/html/lib/built-in-funcs.html#l2h-42).
+            # /usr/share/doc/python/html/library/functions.html#iter).
             for chunk in iter(lambda: file.read(1024 * 64), ''):
                 self.state.f.write(chunk)
                 bytesWritten += len(chunk)
@@ -258,7 +258,7 @@
 
             # Read in and upload the file 64kb at a time, by using the two-arg
             # form of iter (see
-            # /usr/share/doc/python2.4/html/lib/built-in-funcs.html#l2h-42).
+            # /usr/share/doc/python/html/library/functions.html#iter).
             for chunk in iter(lambda: file.read(1024 * 64), ''):
                 self.state.f.write(chunk)
                 bytesWritten += len(chunk)

=== modified file 'lib/lp/services/mailman/monkeypatches/xmlrpcrunner.py'
--- lib/lp/services/mailman/monkeypatches/xmlrpcrunner.py	2012-01-01 02:23:25 +0000
+++ lib/lp/services/mailman/monkeypatches/xmlrpcrunner.py	2012-06-29 14:42:40 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """XMLRPC runner for querying Launchpad."""
@@ -457,7 +457,7 @@
         old_cwd = os.getcwd()
         try:
             os.chdir(lists_dir)
-            extractall(tgz_file)
+            tgz_file.extractall()
         finally:
             os.chdir(old_cwd)
         syslog('xmlrpc', '%s: %s', lists_dir, os.listdir(lists_dir))
@@ -701,36 +701,3 @@
                 # resynchronized.  Be sure to unlock it!
                 mlist.Unlock()
                 statuses[name] = ('resynchronize', 'success')
-
-
-def extractall(tgz_file):
-    """Extract all members of `tgz_file` to the current working directory."""
-    path = '.'
-    # XXX BarryWarsaw 2007-11-13: This is nearly a straight ripoff of
-    # Python 2.5's TarFile.extractall() method, though simplified for our
-    # particular purpose.  When we upgrade Launchpad to Python 2.5, this
-    # function can be removed.
-    directories = []
-    for tarinfo in tgz_file:
-        if tarinfo.isdir():
-            # Extract directory with a safe mode, so that
-            # all files below can be extracted as well.
-            try:
-                os.makedirs(os.path.join(path, tarinfo.name), 0777)
-            except EnvironmentError:
-                pass
-            directories.append(tarinfo)
-        else:
-            tgz_file.extract(tarinfo, path)
-    # Reverse sort directories.
-    directories.sort(lambda a, b: cmp(a.name, b.name))
-    directories.reverse()
-    # Set correct owner, mtime and filemode on directories.
-    for tarinfo in directories:
-        path = os.path.join(path, tarinfo.name)
-        try:
-            tgz_file.chown(tarinfo, path)
-            tgz_file.utime(tarinfo, path)
-            tgz_file.chmod(tarinfo, path)
-        except tarfile.ExtractError, e:
-            log_exception('xmlrpc', 'tarfile: %s', e)

=== modified file 'lib/lp/services/mailman/testing/logwatcher.py'
--- lib/lp/services/mailman/testing/logwatcher.py	2010-08-20 20:31:18 +0000
+++ lib/lp/services/mailman/testing/logwatcher.py	2012-06-29 14:42:40 +0000
@@ -1,11 +1,11 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Watch a log file and wait until it has grown in size."""
 
 __metaclass__ = type
 __all__ = [
-    'BounceWatcher'
+    'BounceWatcher',
     'LogWatcher',
     'MHonArcWatcher',
     'SMTPDWatcher',
@@ -24,14 +24,6 @@
 from Mailman.mm_cfg import LOG_DIR
 
 
-try:
-    # Python 2.5
-    SEEK_END = os.SEEK_END
-except AttributeError:
-    # Python 2.4
-    SEEK_END = 2
-
-
 BREAK_ON_TIMEOUT = bool(os.getenv('BREAK_ON_TIMEOUT'))
 LINES_TO_CAPTURE = 50
 LOG_GROWTH_WAIT_INTERVAL = datetime.timedelta(seconds=10)
@@ -78,7 +70,7 @@
         finally:
             log_file.close()
         self._log_file = open(self._log_path)
-        self._log_file.seek(0, SEEK_END)
+        self._log_file.seek(0, os.SEEK_END)
         self._line_cache = []
         self.last_lines_read = []
 

=== modified file 'lib/lp/services/mime.py'
--- lib/lp/services/mime.py	2010-09-28 19:19:31 +0000
+++ lib/lp/services/mime.py	2012-06-29 14:42:40 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Methods required to customize the mimetypes library."""
@@ -20,10 +20,9 @@
     """
     mimetypes.init()
 
-    # Add support for bz2 encodings, which is not present in python2.5.
-    mimetypes.encodings_map.setdefault('.bz2', 'bzip2')
+    # Add support for .bzip2 as well as .bz2.  Up to Python 3.2 (at least),
+    # only .bz2 is present.
     mimetypes.encodings_map.setdefault('.bzip2', 'bzip2')
-    mimetypes.suffix_map.setdefault('.tbz2', '.tar.bz2')
 
     # XXX: GavinPanella 2008-07-04 bug=229040: A fix has been requested
     # for Intrepid, to add .debdiff to /etc/mime.types, so we may be able

=== modified file 'lib/lp/translations/scripts/copy_distroseries_translations.py'
--- lib/lp/translations/scripts/copy_distroseries_translations.py	2010-08-20 20:31:18 +0000
+++ lib/lp/translations/scripts/copy_distroseries_translations.py	2012-06-29 14:42:40 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Copy `DistroSeries` translations from its parent series."""
@@ -87,17 +87,14 @@
     copy_failed = False
 
     try:
-        # XXX JeroenVermeulen 2008-02-12: In python2.5 and up we'll be
-        # able to combine these two try blocks.  In 2.4, we can't.
-        try:
-            # Do the actual work.
-            distroseries.copyTranslationsFromParent(txn, logger)
-        except:
-            copy_failed = True
-            # Give us a fresh transaction for proper cleanup.
-            txn.abort()
-            txn.begin()
-            raise
+        # Do the actual work.
+        distroseries.copyTranslationsFromParent(txn, logger)
+    except:
+        copy_failed = True
+        # Give us a fresh transaction for proper cleanup.
+        txn.abort()
+        txn.begin()
+        raise
     finally:
         try:
             statekeeper.restore()
@@ -114,4 +111,3 @@
             # well.
             if not copy_failed:
                 raise
-


Follow ups