Skip to content
Commits on Source (3)
......@@ -30,7 +30,10 @@ import os
import fcntl
import time
import random
from urllib2 import URLError
try:
from urllib.errors import URLError
except ImportError:
from urllib2 import URLError
import piupartslib
from piupartslib.packagesdb import LogfileExists
......
......@@ -38,7 +38,10 @@ import hashlib
import pickle
import random
import fcntl
from urllib2 import HTTPError, URLError
try:
from urllib.errors import HTTPError, URLError
except ImportError:
from urllib2 import HTTPError, URLError
from collections import deque
# if python-rpy2 ain't installed, we don't draw fancy graphs
......
......@@ -20,7 +20,11 @@
import bz2
import lzma
import zlib
import urllib2
try:
from urllib.request import urlopen
from urllib.error import HTTPError
except ImportError:
from urllib2 import urlopen, HTTPError
import conf
......@@ -82,12 +86,13 @@ def open_packages_url(url):
socket = None
for ext in ['.xz', '.bz2', '.gz', '']:
try:
socket = urllib2.urlopen(url + ext)
except urllib2.HTTPError as httperror:
socket = urlopen(url + ext)
except HTTPError as httperror:
pass
else:
break
if socket is None:
# FIXME: I don't think httperror will be defined here
raise httperror
url = socket.geturl()
if ext == '.bz2':
......
......@@ -24,7 +24,10 @@
#
import ConfigParser
import UserDict
try:
from collections import UserDict
except ImportError:
from UserDict import UserDict
import subprocess
import collections
import re
......@@ -46,10 +49,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():
......@@ -148,10 +151,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,
......
......@@ -32,7 +32,10 @@ import random
import stat
import tempfile
import time
import UserDict
try:
from collections import UserDict
except ImportError:
from UserDict import UserDict
import apt_pkg
import piupartslib
......@@ -54,10 +57,10 @@ def rfc822_like_header_parse(input):
return headers
class Package(UserDict.UserDict):
class Package(UserDict):
def __init__(self, headers):
UserDict.UserDict.__init__(self)
UserDict.__init__(self)
self.headers = headers
for header in headers:
name, value = header.split(":", 1)
......@@ -163,10 +166,10 @@ class Package(UserDict.UserDict):
output_file.write("".join(self.headers))
class PackagesFile(UserDict.UserDict):
class PackagesFile(UserDict):
def __init__(self):
UserDict.UserDict.__init__(self)
UserDict.__init__(self)
self._urllist = []
def load_packages_urls(self, urls, restrict_packages=None):
......
......@@ -18,16 +18,16 @@ class DependencyParserTests(unittest.TestCase):
def testEmpty(self):
deps, names = self.parse("")
self.failUnlessEqual(deps, [])
self.assertEqual(deps, [])
def testSingle(self):
deps, names = self.parse("foo")
self.failUnlessEqual(names, [["foo"]])
self.assertEqual(names, [["foo"]])
def testTwo(self):
deps, names = self.parse("foo, bar")
self.failUnlessEqual(names, [["foo"], ["bar"]])
self.assertEqual(names, [["foo"], ["bar"]])
def testAlternatives(self):
deps, names = self.parse("foo, bar | foobar")
self.failUnlessEqual(names, [["foo"], ["bar", "foobar"]])
self.assertEqual(names, [["foo"], ["bar", "foobar"]])
......@@ -100,70 +100,70 @@ class IsBrokenSymlinkTests(unittest.TestCase):
shutil.rmtree(self.testdir)
def testRelativeBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"relative-broken"))
def testRelativeBrokenToSymlink(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"relative-broken-to-symlink"))
def testAbsoluteBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"absolute-broken"))
def testAbsoluteBrokenToSymlink(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"absolute-broken-to-symlink"))
def testTrailingSlashBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"trailing-slash-broken"))
def testSelfLoopBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"selfloop"))
def testExpandingSelfLoopBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"explode"))
def testAbsoluteSelfLoopBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"absolute-selfloop"))
def testSubdirSelfLoopBroken(self):
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"dir/selfloop"))
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"dir/selfloop1"))
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"dir/subdir/selfloop"))
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"dir/subdir/selfloop1"))
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"dir/subdir/selfloop2"))
self.failUnless(is_broken_symlink(self.testdir, self.testdir,
self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
"dir/subdir/selfloop3"))
def testRelativeWorks(self):
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"relative-works"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"relative-works"))
def testRelativeWorksToSymlink(self):
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"relative-works-to-symlink"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"relative-works-to-symlink"))
def testAbsoluteWorks(self):
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"absolute-works"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"absolute-works"))
def testAbsoluteWorksToSymlink(self):
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"absolute-works-to-symlink"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"absolute-works-to-symlink"))
def testTrailingSlashWorks(self):
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"trailing-slash-works"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"trailing-slash-works"))
def testMultiLevelNestedSymlinks(self):
# target/first-link -> ../target/second-link -> ../target
......@@ -171,8 +171,8 @@ class IsBrokenSymlinkTests(unittest.TestCase):
os.mkdir(os.path.join(self.testdir, "target"))
self.symlink("../target", "target/second-link")
self.symlink("../target/second-link", "target/first-link")
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"target/first-link"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"target/first-link"))
def testMultiLevelNestedAbsoluteSymlinks(self):
# first-link -> /second-link/final-target
......@@ -182,5 +182,5 @@ class IsBrokenSymlinkTests(unittest.TestCase):
os.mkdir(os.path.join(self.testdir, "final-dir/final-target"))
self.symlink("/second-link/final-target", "first-link")
self.symlink("/final-dir", "second-link")
self.failIf(is_broken_symlink(self.testdir, self.testdir,
"first-link"))
self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
"first-link"))
......@@ -59,15 +59,15 @@ class PackagesDbTests(unittest.TestCase):
def testNoPackages(self):
p = self.reserve("")
self.failUnlessEqual(p, None)
self.assertEqual(p, None)
def testNoDeps(self):
p = self.reserve("""\
Package: foo
Version: 1.0-1
""")
self.failIfEqual(p, None)
self.failUnlessEqual(p["Package"], "foo")
self.assertNotEqual(p, None)
self.assertEqual(p["Package"], "foo")
if __name__ == "__main__":
......