summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-10-18 11:51:44 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-10-18 11:51:44 +0200
commit3bf6b76611bf0b148d495e2e4aae08546e54fa94 (patch)
tree52a21ae6f4742644a5709b3a160c862d818e821f
parentd9deeabe21f828ae4301c4aab5073f775f954e25 (diff)
downloadpython-apt-3bf6b76611bf0b148d495e2e4aae08546e54fa94.tar.gz
fix compat issues with python3
-rw-r--r--apt/utils.py4
-rw-r--r--aptsources/distinfo.py28
-rw-r--r--aptsources/distro.py5
-rw-r--r--aptsources/sourceslist.py15
-rw-r--r--debian/changelog5
-rw-r--r--tests/test_utils.py12
6 files changed, 36 insertions, 33 deletions
diff --git a/apt/utils.py b/apt/utils.py
index 8fc69215..49e8bed5 100644
--- a/apt/utils.py
+++ b/apt/utils.py
@@ -29,10 +29,10 @@ def get_maintenance_end_date(release_date, m_months):
its is supported as input
"""
# calc end date
- years = m_months / 12
+ years = m_months // 12
months = m_months % 12
support_end_year = (release_date.year + years +
- (release_date.month + months)/12)
+ (release_date.month + months)//12)
support_end_month = (release_date.month + months) % 12
# special case: this happens when e.g. doing 2010-06 + 18 months
if support_end_month == 0:
diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py
index 6374f185..a69f944a 100644
--- a/aptsources/distinfo.py
+++ b/aptsources/distinfo.py
@@ -22,11 +22,11 @@
# USA
import errno
+import logging
import os
import gettext
from os import getenv
from subprocess import Popen, PIPE
-import ConfigParser
import re
import apt_pkg
@@ -166,9 +166,9 @@ class DistInfo(object):
try:
dist = Popen(["lsb_release", "-i", "-s"],
stdout=PIPE).communicate()[0].strip()
- except OSError, exc:
+ except OSError as exc:
if exc.errno != errno.ENOENT:
- print 'WARNING: lsb_release failed, using defaults:', exc
+ logging.warn('lsb_release failed, using defaults:' % exc)
dist = "Debian"
self.dist = dist
@@ -232,7 +232,7 @@ class DistInfo(object):
mirror_data = filter(match_mirror_line.match,
[x.strip() for x in open(value)])
except Exception:
- print "WARNING: Failed to read mirror file"
+ logging.warn("Failed to read mirror file")
mirror_data = []
for line in mirror_data:
if line.startswith("#LOC:"):
@@ -286,17 +286,17 @@ class DistInfo(object):
if __name__ == "__main__":
d = DistInfo("Ubuntu", "/usr/share/python-apt/templates")
- print d.changelogs_uri
+ logging.info(d.changelogs_uri)
for template in d.templates:
- print "\nSuite: %s" % template.name
- print "Desc: %s" % template.description
- print "BaseURI: %s" % template.base_uri
- print "MatchURI: %s" % template.match_uri
+ logging.info("\nSuite: %s" % template.name)
+ logging.info("Desc: %s" % template.description)
+ logging.info("BaseURI: %s" % template.base_uri)
+ logging.info("MatchURI: %s" % template.match_uri)
if template.mirror_set != {}:
- print "Mirrors: %s" % template.mirror_set.keys()
+ logging.info("Mirrors: %s" % template.mirror_set.keys())
for comp in template.components:
- print " %s -%s -%s" % (comp.name,
- comp.description,
- comp.description_long)
+ logging.info(" %s -%s -%s" % (comp.name,
+ comp.description,
+ comp.description_long))
for child in template.children:
- print " %s" % child.description
+ logging.info(" %s" % child.description)
diff --git a/aptsources/distro.py b/aptsources/distro.py
index 23192f50..d4b65645 100644
--- a/aptsources/distro.py
+++ b/aptsources/distro.py
@@ -22,6 +22,7 @@
# USA
import gettext
+import logging
import re
import os
import sys
@@ -451,9 +452,9 @@ def _lsb_release():
# Convert to unicode string, needed for Python 3.1
out = out.decode("utf-8")
result.update(l.split(":\t") for l in out.split("\n") if ':\t' in l)
- except OSError, exc:
+ except OSError as exc:
if exc.errno != errno.ENOENT:
- print 'WARNING: lsb_release failed, using defaults:', exc
+ logging.warn('lsb_release failed, using defaults:' % exc)
return result
diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py
index 76bea43a..0c4335ec 100644
--- a/aptsources/sourceslist.py
+++ b/aptsources/sourceslist.py
@@ -25,6 +25,7 @@
import gettext
import glob
+import logging
import os.path
import re
import shutil
@@ -346,7 +347,7 @@ class SourcesList(object):
source = SourceEntry(line, file)
self.list.append(source)
except:
- print "could not open file '%s'" % file
+ logging.error("could not open file '%s'" % file)
else:
f.close()
@@ -437,14 +438,14 @@ if __name__ == "__main__":
sources = SourcesList()
for entry in sources:
- print entry.str()
+ logging.info("entry %s" % entry.str())
#print entry.uri
mirror = is_mirror("http://archive.ubuntu.com/ubuntu/",
"http://de.archive.ubuntu.com/ubuntu/")
- print "is_mirror(): %s" % mirror
+ logging.info("is_mirror(): %s" % mirror)
- print is_mirror("http://archive.ubuntu.com/ubuntu",
- "http://de.archive.ubuntu.com/ubuntu/")
- print is_mirror("http://archive.ubuntu.com/ubuntu/",
- "http://de.archive.ubuntu.com/ubuntu")
+ logging.info(is_mirror("http://archive.ubuntu.com/ubuntu",
+ "http://de.archive.ubuntu.com/ubuntu/"))
+ logging.info(is_mirror("http://archive.ubuntu.com/ubuntu/",
+ "http://de.archive.ubuntu.com/ubuntu"))
diff --git a/debian/changelog b/debian/changelog
index 817d34bd..3bf12153 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,14 +1,15 @@
-python-apt (0.7.98.1ubuntu1) UNRELEASEDmaverick; urgency=low
+python-apt (0.7.98.1ubuntu1) natty; urgency=low
[ Michael Vogt ]
* merged from debian/sid, remaining changes:
- updated mirror list
+ - compat fixes for 3.x (pending upstream inclusion)
[ Jeremy Bicha ]
* data/templates/Ubuntu.info.in:
- add natty, LP:661578
- -- Michael Vogt <michael.vogt@ubuntu.com> Fri, 15 Oct 2010 10:30:58 +0200
+ -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 18 Oct 2010 10:55:00 +0200
python-apt (0.7.98.1) unstable; urgency=low
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 19dd977d..23511f32 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -20,7 +20,7 @@ class TestUtils(unittest.TestCase):
from apt.utils import get_maintenance_end_date
months_of_support = 18
# test historic releases, jaunty
- release_date = datetime.datetime(2009, 04, 23)
+ release_date = datetime.datetime(2009, 4, 23)
(end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
self.assertEqual(end_year, 2010)
self.assertEqual(end_month, 10)
@@ -28,25 +28,25 @@ class TestUtils(unittest.TestCase):
release_date = datetime.datetime(2009, 10, 29)
(end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
self.assertEqual(end_year, 2011)
- self.assertEqual(end_month, 04)
+ self.assertEqual(end_month, 4)
# test maverick
release_date = datetime.datetime(2010, 10, 10)
(end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
self.assertEqual(end_year, 2012)
- self.assertEqual(end_month, 04)
+ self.assertEqual(end_month, 4)
# test with modulo zero
- release_date = datetime.datetime(2010, 06, 10)
+ release_date = datetime.datetime(2010, 6, 10)
(end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
self.assertEqual(end_year, 2011)
self.assertEqual(end_month, 12)
# test dapper
months_of_support = 60
- release_date = datetime.datetime(2008, 04, 24)
+ release_date = datetime.datetime(2008, 4, 24)
(end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
self.assertEqual(end_year, 2013)
- self.assertEqual(end_month, 04)
+ self.assertEqual(end_month, 4)
# what datetime says
#d = datetime.timedelta(18*30)