From b7b608bf2c66e7466313ea02568348aea9cc29ba Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:01:26 +0100 Subject: cleanup based on feedback from juliank --- apt/cache.py | 10 ++++++++-- apt/debfile.py | 19 +++++++++++++------ debian/changelog | 6 +++--- tests/test_debfile.py | 12 +++++++----- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index 8a456715..b4d67fa5 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -46,7 +46,13 @@ class LockFailedException(IOError): class Cache(object): """Dictionary-like package cache. - The dictionary of this class contains all available packages. + The APT cache file contains a hash table mapping names of binary + packages to their metadata. A Cache object is the in-core + representation of the same. It provides access to APTs idea of the + list of available packages. + + The cache can be used like a mapping from package names to Package + objects (although only getting items is supported). Keyword arguments: progress -- a OpProgress object @@ -510,7 +516,7 @@ class Cache(object): self._callbacks[name].append(callback) def actiongroup(self): - """Return an action group object for the current cache. + """Return an `ActionGroup` object for the current cache. Action groups can be used to speedup actions. The action group is active as soon as it is created, and disabled when the object is diff --git a/apt/debfile.py b/apt/debfile.py index 104b0814..5b9274b2 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -53,6 +53,7 @@ class DebPackage(object): self.pkgname = "" self._sections = {} self._need_pkgs = [] + self._check_was_run = False self._failure_string = "" if filename: self.open(filename) @@ -68,7 +69,8 @@ class DebPackage(object): control = self._debfile.control.extractdata("control") self._sections = apt_pkg.TagSection(control) self.pkgname = self._sections["Package"] - + self._check_was_run = False + def __getitem__(self, key): return self._sections[key] @@ -393,6 +395,8 @@ class DebPackage(object): """Check if the package is installable.""" self._dbg(3, "check") + self._check_was_run = True + # check arch if not "Architecture" in self._sections: self._dbg(1, "ERROR: no architecture field") @@ -472,8 +476,8 @@ class DebPackage(object): def missing_deps(self): """Return missing dependencies.""" self._dbg(1, "Installing: %s" % self._need_pkgs) - if not self._need_pkgs: - self.check() + if not self._check_was_run: + raise ValueError("property only available after check() was run") return self._need_pkgs @property @@ -485,8 +489,8 @@ class DebPackage(object): install = [] remove = [] unauthenticated = [] - if not self._cache: - self.check() + if not self._check_was_run: + raise ValueError("property only available after check() was run") for pkg in self._cache: if pkg.marked_install or pkg.marked_upgrade: install.append(pkg.name) @@ -641,7 +645,8 @@ class DscSrcPackage(DebPackage): "source package '%s' that builds %s\n") % (self.pkgname, " ".join(self.binaries)) self._sections["Description"] = s - + self._check_was_run = False + def check(self): """Check if the package is installable..""" if not self.check_conflicts(): @@ -649,6 +654,8 @@ class DscSrcPackage(DebPackage): if self._cache[pkgname]._pkg.essential: raise Exception(_("An essential package would be removed")) self._cache[pkgname].mark_delete() + # properties are ok now + self._check_was_run = True # FIXME: a additional run of the check_conflicts() # after _satisfy_depends() should probably be done return self._satisfy_depends(self.depends) diff --git a/debian/changelog b/debian/changelog index 27eb8e97..cc922735 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,13 +26,13 @@ python-apt (0.8.2) UNRELEASED; urgency=low - set Dir::bin::dpkg if a alternate rootdir is given (LP: #885895) * build fixes for the apt in experimental + * apt/debfile.py: raise error when accessing require_changes and + missing_deps without calling check() before, thanks to + Tshepang Lekhonkhobe (closes: #624379) [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) * grammar fix in the cache.py doc (closes: #626610) - * apt/debfile.py: Remove the need to explcitly call check() in order - to get output from require_changes and missing_deps - (closes: #624379) -- Michael Vogt Wed, 19 Oct 2011 18:03:42 +0200 diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 501b8f61..e6c475d3 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -88,11 +88,6 @@ class TestDebfilee(unittest.TestCase): "Samuel Lidén Borell ") def test_content(self): - # no python-debian for python3 yet, so fail gracefully - try: - import debian - except ImportError: - return # normal deb = apt.debfile.DebPackage(cache=self.cache) deb.open(os.path.join("data", "test_debs", "gdebi-test11.deb")) @@ -119,6 +114,13 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") self.assertEqual(deb.filelist, ["./", "usr/", "usr/bin/"]) + def test_check_exception(self): + deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") + with self.assertRaises(ValueError): + deb.missing_deps + deb.check() + deb.missing_deps + def test_no_supported_data_tar(self): # ensure that a unknown data.tar.xxx raises a exception raised = False -- cgit v1.2.3 From 0af443d9a182b0fec5f9963edef3c1f1908e831f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:06:30 +0100 Subject: cleanup --- apt/cache.py | 14 +++++++------- apt/debfile.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apt/cache.py b/apt/cache.py index b4d67fa5..96b38a57 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -46,13 +46,13 @@ class LockFailedException(IOError): class Cache(object): """Dictionary-like package cache. - The APT cache file contains a hash table mapping names of binary - packages to their metadata. A Cache object is the in-core - representation of the same. It provides access to APTs idea of the - list of available packages. - - The cache can be used like a mapping from package names to Package - objects (although only getting items is supported). + The APT cache file contains a hash table mapping names of binary + packages to their metadata. A Cache object is the in-core + representation of the same. It provides access to APTs idea of the + list of available packages. + + The cache can be used like a mapping from package names to Package + objects (although only getting items is supported). Keyword arguments: progress -- a OpProgress object diff --git a/apt/debfile.py b/apt/debfile.py index 5b9274b2..277262d7 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -477,7 +477,7 @@ class DebPackage(object): """Return missing dependencies.""" self._dbg(1, "Installing: %s" % self._need_pkgs) if not self._check_was_run: - raise ValueError("property only available after check() was run") + raise AttributeError("property only available after check() was run") return self._need_pkgs @property @@ -490,7 +490,7 @@ class DebPackage(object): remove = [] unauthenticated = [] if not self._check_was_run: - raise ValueError("property only available after check() was run") + raise AttributeError("property only available after check() was run") for pkg in self._cache: if pkg.marked_install or pkg.marked_upgrade: install.append(pkg.name) -- cgit v1.2.3 From b1c645c534e14bc21da638aefd54d2c59085f3ec Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:09:44 +0100 Subject: tests/test_debfile.py: fix test after previous exception change --- tests/test_debfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_debfile.py b/tests/test_debfile.py index e6c475d3..89f50d2a 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -116,7 +116,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading def test_check_exception(self): deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") - with self.assertRaises(ValueError): + with self.assertRaises(AttributeError): deb.missing_deps deb.check() deb.missing_deps -- cgit v1.2.3 From ff886d6a8c468a31433013250aed337dfe0770cc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:32:56 +0100 Subject: tests/test_debfile.py: remove debug print --- tests/test_debfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 89f50d2a..7619f33d 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -133,7 +133,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading self.assertTrue(raised) def test_multiarch_deb(self): - print apt_pkg.get_architectures() + #print apt_pkg.get_architectures() if apt_pkg.get_architectures() != ["amd64", "i386"]: logging.warn("skipping test because running on a non-multiarch system") return -- cgit v1.2.3 From fb4ef05de0a64f75f2896d9e74c88a3bb3db00c7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:36:46 +0100 Subject: apt/package.py: use lt() instead of cmp() --- apt/package.py | 4 ++-- debian/changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apt/package.py b/apt/package.py index cb373c2e..45d6044b 100644 --- a/apt/package.py +++ b/apt/package.py @@ -707,8 +707,8 @@ class Package(object): return '' % (self._pkg.name, self._pkg.architecture, self._pkg.id) - def __cmp__(self, other): - return cmp(self.name, other.name) + def __lt__(self, other): + return self.name < other.name def candidate(self): """Return the candidate version of the package. diff --git a/debian/changelog b/debian/changelog index cc922735..fece12fb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,7 +18,7 @@ python-apt (0.8.2) UNRELEASED; urgency=low * apt/cache.py: - remove "print" when creating dirs in apt.Cache(rootdir=dir), thanks to Martin Pitt - - add __cmp__ to apt.Package so that sort() sorts by name + - add __lt__ to apt.Package so that sort() sorts by name on list of package objects * debian/control: - add recommends to xz-lzma to ensure we have the unlzma command -- cgit v1.2.3 From bdf3dfdca30b0d822d267b8453dd1101e864d276 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:45:23 +0100 Subject: tests/test_apt_cache.py: fix test failure by explicitely setting rootdir --- tests/test_apt_cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 0d80f617..74d94ed8 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -182,7 +182,7 @@ class TestAptCache(unittest.TestCase): apt_pkg.config.set("dir::etc::sourceparts", old_source_parts) def test_package_cmp(self): - cache = apt.Cache() + cache = apt.Cache(rootdir="/") l = [] l.append(cache["libc6"]) l.append(cache["xterm"]) -- cgit v1.2.3 From ea348ef49c34f22c8f06cdbcbcae3c2fbc7652fd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:51:57 +0100 Subject: tests/test_debfile.py: fix test on python2.6 --- tests/test_debfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 7619f33d..30a2be0a 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -116,8 +116,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading def test_check_exception(self): deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") - with self.assertRaises(AttributeError): - deb.missing_deps + self.assertRaises(AttributeError, lambda: deb.missing_deps) deb.check() deb.missing_deps -- cgit v1.2.3 From d76a13a50fda292fe011a86f2b761d5753dc1470 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:58:06 +0100 Subject: tests/test_debfile.py: remove unneeded debug print --- tests/test_debfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 30a2be0a..d7c38b3d 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -137,7 +137,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading logging.warn("skipping test because running on a non-multiarch system") return deb = apt.debfile.DebPackage("./data/test_debs/multiarch-test1_i386.deb") - print deb.missing_deps() + #print deb.missing_deps() -- cgit v1.2.3 From d686a36d94e909eefc13403391ee60938f54df5c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2011 14:30:13 +0100 Subject: releasing version 0.8.2 --- debian/changelog | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 4cde2d21..4a90e907 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.8.2) UNRELEASED; urgency=low +python-apt (0.8.2) unstable; urgency=low [ Michael Vogt ] * merged from ubuntu: @@ -51,7 +51,7 @@ python-apt (0.8.2) UNRELEASED; urgency=low * fixed a typo, changed "Open Source software" to "free and open-source software" (LP: #500940) - -- Michael Vogt Wed, 19 Oct 2011 18:03:42 +0200 + -- Michael Vogt Thu, 01 Dec 2011 14:14:42 +0100 python-apt (0.8.1) unstable; urgency=low @@ -81,7 +81,6 @@ python-apt (0.8.1) unstable; urgency=low that needs universe enabled as well (plus add test) * apt/progress/gtk2.py: - update to the latest vte API for child-exited (LP: #865388) - * tests/test_apt_cache.py: -- Michael Vogt Wed, 19 Oct 2011 16:39:13 +0200 -- cgit v1.2.3