[Piuparts-commits] [piuparts] 02/05: make imports py3 compatible

Holger Levsen holger at moszumanska.debian.org
Mon Apr 27 15:12:48 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit 323d39a7a6546923809635c2d909d6af16f65709
Author: Börni <boerni at gmail.com>
Date:   Sun Apr 19 15:41:54 2015 +0200

    make imports py3 compatible
---
 master-bin/detect_well_known_errors.py |  1 -
 piuparts-master-backend.py             |  1 -
 piuparts-report.py                     |  1 -
 piuparts-slave.py                      |  1 -
 piuparts.py                            |  1 -
 piupartslib/__init__.py                |  6 +++---
 piupartslib/conf.py                    | 24 ++++++++++++++++--------
 tests/unittests.py                     | 10 +++++++---
 8 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/master-bin/detect_well_known_errors.py b/master-bin/detect_well_known_errors.py
index a3346a5..e80dd2e 100755
--- a/master-bin/detect_well_known_errors.py
+++ b/master-bin/detect_well_known_errors.py
@@ -20,7 +20,6 @@
 # with this program; if not, see <http://www.gnu.org/licenses/>.
 
 
-import ConfigParser
 import os
 import sys
 import time
diff --git a/piuparts-master-backend.py b/piuparts-master-backend.py
index 2d0bbb0..9f4cbe8 100644
--- a/piuparts-master-backend.py
+++ b/piuparts-master-backend.py
@@ -27,7 +27,6 @@ Lars Wirzenius <liw at iki.fi>
 
 import sys
 import logging
-import ConfigParser
 import os
 import fcntl
 import time
diff --git a/piuparts-report.py b/piuparts-report.py
index 1375f8b..e182a4b 100644
--- a/piuparts-report.py
+++ b/piuparts-report.py
@@ -31,7 +31,6 @@ import os
 import sys
 import time
 import logging
-import ConfigParser
 import shutil
 import re
 import string
diff --git a/piuparts-slave.py b/piuparts-slave.py
index ab26c8c..ec2d76c 100644
--- a/piuparts-slave.py
+++ b/piuparts-slave.py
@@ -34,7 +34,6 @@ from signal import alarm, signal, SIGALRM, SIGINT, SIGKILL, SIGHUP
 import subprocess
 import fcntl
 import random
-import ConfigParser
 import apt_pkg
 
 import piupartslib.conf
diff --git a/piuparts.py b/piuparts.py
index 4d1db23..450d09d 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -40,7 +40,6 @@ import time
 import logging
 import optparse
 import sys
-import commands
 import tempfile
 import shutil
 import os
diff --git a/piupartslib/__init__.py b/piupartslib/__init__.py
index a496bf4..6863ea3 100644
--- a/piupartslib/__init__.py
+++ b/piupartslib/__init__.py
@@ -23,9 +23,9 @@ import zlib
 import urllib2
 
 
-import conf
-import dependencyparser
-import packagesdb
+from . import conf
+from . import dependencyparser
+from . import packagesdb
 
 
 class DecompressedStream():
diff --git a/piupartslib/conf.py b/piupartslib/conf.py
index e06be68..51e67ec 100644
--- a/piupartslib/conf.py
+++ b/piupartslib/conf.py
@@ -24,8 +24,16 @@
 # in a configuration file, that's why).
 #
 
-import ConfigParser
-import UserDict
+try:
+    import configparser  # py3
+except ImportError:
+    import ConfigParser as configparser  # py2
+
+try:
+    from collections import UserDict  # py3
+except ImportError:
+    from UserDict import UserDict  # py2
+
 import subprocess
 import collections
 import re
@@ -47,10 +55,10 @@ class MissingMandatorySetting(Exception):
             (key, filename),
 
 
-class Config(UserDict.UserDict):
+class Config(UserDict):
 
     def __init__(self, section, defaults, mandatory=[], defaults_section=None):
-        UserDict.UserDict.__init__(self)
+        UserDict.__init__(self)
         self._section = section
         self._defaults_section = defaults_section
         for key, value in defaults.iteritems():
@@ -58,7 +66,7 @@ class Config(UserDict.UserDict):
         self._mandatory = mandatory
 
     def read(self, filename):
-        cp = ConfigParser.ConfigParser()
+        cp = configparser.ConfigParser()
         cp.read(filename)
         if not cp.has_section(self._section):
             raise MissingSection(filename, self._section)
@@ -149,10 +157,10 @@ class Config(UserDict.UserDict):
         return self["arch"]
 
 
-class DistroConfig(UserDict.UserDict):
+class DistroConfig(UserDict):
 
     def __init__(self, filename, mirror):
-        UserDict.UserDict.__init__(self)
+        UserDict.__init__(self)
         self._mirror = mirror
         self._defaults = {
             "uri": None,
@@ -162,7 +170,7 @@ class DistroConfig(UserDict.UserDict):
                 "depends": None,
                 "candidates": None,
         }
-        cp = ConfigParser.SafeConfigParser()
+        cp = configparser.SafeConfigParser()
         cp.read(filename)
         for section in cp.sections():
             self[section] = dict(self._defaults)
diff --git a/tests/unittests.py b/tests/unittests.py
index ab65804..212839b 100644
--- a/tests/unittests.py
+++ b/tests/unittests.py
@@ -1,7 +1,11 @@
 # -*- coding: utf-8 -*-
 
 import os
-import StringIO
+try:
+    from io import StringIO  # py3
+except ImportError:
+    from StringIO import StringIO  # py2
+
 import unittest
 
 
@@ -40,7 +44,7 @@ class FakeLogDB(piupartslib.packagesdb.LogDB):
     def open_file(self, pathname, mode):
         vdir, base = self._parse(pathname)
         self.dict[vdir].append(base)
-        return StringIO.StringIO()
+        return StringIO()
 
     def remove_file(self, pathname):
         vdir, base = self._parse(pathname)
@@ -55,7 +59,7 @@ class PackagesDbTests(unittest.TestCase):
 
     def new_db(self, packages_file_contents):
         db = piupartslib.packagesdb.PackagesDB(FakeLogDB())
-        db.read_packages_file(StringIO.StringIO(packages_file_contents))
+        db.read_packages_file(StringIO(packages_file_contents))
         return db
 
     def reserve(self, packages_file_contents):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list