From 9a4aa5da4bf35d3ba2f5417b0496a7f2f45e8847 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Wed, 7 Apr 2010 10:13:33 +0100 Subject: [PATCH] Allow passing the location of pkgcache to DebianDistribution Avoids having the unittests try to use the host's cache, giving an error on non-Debian systems. Reported by Aleksey Lim. --- tests/basetest.py | 3 ++- tests/dpkg/pkgcache.bin | 0 tests/testdistro.py | 4 +++- zeroinstall/injector/distro.py | 11 ++++++----- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 tests/dpkg/pkgcache.bin diff --git a/tests/basetest.py b/tests/basetest.py index 8fc660e..533106c 100755 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -64,7 +64,8 @@ class BaseTest(unittest.TestCase): self.old_path = os.environ['PATH'] os.environ['PATH'] = dpkgdir + ':' + self.old_path - distro._host_distribution = distro.DebianDistribution(dpkgdir) + distro._host_distribution = distro.DebianDistribution(dpkgdir + '/status', + dpkgdir + '/pkgcache.bin') def tearDown(self): shutil.rmtree(self.config_home) diff --git a/tests/dpkg/pkgcache.bin b/tests/dpkg/pkgcache.bin new file mode 100644 index 0000000..e69de29 diff --git a/tests/testdistro.py b/tests/testdistro.py index 7f16f33..c289902 100755 --- a/tests/testdistro.py +++ b/tests/testdistro.py @@ -66,7 +66,9 @@ class TestDistro(BaseTest): def testDebian(self): dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg') - host = distro.DebianDistribution(os.path.join(dpkgdir, 'status')) + host = distro.DebianDistribution( + os.path.join(dpkgdir, 'status'), + os.path.join(dpkgdir, 'pkgcache.bin')) self.assertEquals(2, len(host.versions)) diff --git a/zeroinstall/injector/distro.py b/zeroinstall/injector/distro.py index a1f7522..fb3b11e 100644 --- a/zeroinstall/injector/distro.py +++ b/zeroinstall/injector/distro.py @@ -236,9 +236,9 @@ class DebianDistribution(CachedDistribution): cache_leaf = 'dpkg-status.cache' - def __init__(self, dpkg_status): + def __init__(self, dpkg_status, pkgcache): CachedDistribution.__init__(self, dpkg_status) - self.apt_cache = Cache('apt-cache-cache', '/var/cache/apt/pkgcache.bin') + self.apt_cache = Cache('apt-cache-cache', pkgcache) def generate_cache(self): cache = [] @@ -395,14 +395,15 @@ def get_host_distribution(): @rtype: L{Distribution}""" global _host_distribution if not _host_distribution: - _dpkg_db_status = '/var/lib/dpkg/status' + dpkg_db_status = '/var/lib/dpkg/status' + pkgcache = '/var/cache/apt/pkgcache.bin' _rpm_db = '/var/lib/rpm/Packages' _gentoo_db = '/var/db/pkg' if os.path.isdir(_gentoo_db): _host_distribution = GentooDistribution(_gentoo_db) - elif os.access(_dpkg_db_status, os.R_OK): - _host_distribution = DebianDistribution(_dpkg_db_status) + elif os.access(dpkg_db_status, os.R_OK): + _host_distribution = DebianDistribution(dpkg_db_status, pkgcache) elif os.path.isfile(_rpm_db): _host_distribution = RPMDistribution(_rpm_db) else: -- 2.11.4.GIT