From 628d7caf9ca6ee819398a4b88c23e42094fe2c10 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 10 Nov 2011 17:20:58 +0100 Subject: fix build against apt in experimental --- tests/test_debfile.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests/test_debfile.py') diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 951c2afe..501b8f61 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -87,7 +87,7 @@ class TestDebfilee(unittest.TestCase): self.assertEqual(deb["Maintainer"], "Samuel Lidén Borell ") - def testContent(self): + def test_content(self): # no python-debian for python3 yet, so fail gracefully try: import debian @@ -130,6 +130,17 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading # we need to support python2.6 self.assertTrue(raised) + def test_multiarch_deb(self): + print apt_pkg.get_architectures() + if apt_pkg.get_architectures() != ["amd64", "i386"]: + 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() + + + + if __name__ == "__main__": #logging.basicConfig(level=logging.DEBUG) unittest.main() -- cgit v1.2.3 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(-) (limited to 'tests/test_debfile.py') 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 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(-) (limited to 'tests/test_debfile.py') 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(-) (limited to 'tests/test_debfile.py') 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 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(-) (limited to 'tests/test_debfile.py') 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(-) (limited to 'tests/test_debfile.py') 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 c8bfdda85fbd2df250fbc6d3faeb2bd5875a77d6 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2011 13:32:42 +0100 Subject: py3 fixes/clean --- apt/progress/base.py | 2 ++ tests/test_debfile.py | 4 ++-- tests/test_utils.py | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'tests/test_debfile.py') diff --git a/apt/progress/base.py b/apt/progress/base.py index 4943978c..c2a9a9c8 100644 --- a/apt/progress/base.py +++ b/apt/progress/base.py @@ -192,12 +192,14 @@ class InstallProgress(object): # and the execution continues in the # parent code leading to very confusing bugs try: + raise Exception("foo") os._exit(obj.do_install(self.write_stream.fileno())) except AttributeError: os._exit(os.spawnlp(os.P_WAIT, "dpkg", "dpkg", "--status-fd", str(self.write_stream.fileno()), "-i", obj)) except Exception as e: + os.write(self.writefd, "pmerror:::%s" % e) sys.stderr.write("%s\n" % e) os._exit(apt_pkg.PackageManager.RESULT_FAILED) diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 501b8f61..56410153 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -131,12 +131,12 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading self.assertTrue(raised) def test_multiarch_deb(self): - print apt_pkg.get_architectures() if apt_pkg.get_architectures() != ["amd64", "i386"]: 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() + res = deb.check() + # FIXME: do something sensible with the multiarch test diff --git a/tests/test_utils.py b/tests/test_utils.py index 23511f32..26ee0bff 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,7 +7,6 @@ # notice and this notice are preserved. import sys -sys.path.insert(0, "..") import apt_pkg import apt.utils import datetime -- cgit v1.2.3 From fb595849bc7149619b3e47b65f145a1f66fc7dbe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2011 13:45:58 +0100 Subject: fix debfile binary test for py3 --- apt/debfile.py | 11 +++++++++-- tests/test_debfile.py | 5 ----- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'tests/test_debfile.py') diff --git a/apt/debfile.py b/apt/debfile.py index 104b0814..4a82842a 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -525,12 +525,19 @@ class DebPackage(object): @staticmethod def to_strish(in_data): + # helper for py3 compat, in_data is str in py2 and bytes in py3 + def my_ord(c): + if type(c) == int: + return c + else: + return ord(c) + # convert s = "" for c in in_data: - if ord(c) < 10 or ord(c) > 127: + if my_ord(c) < 10 or my_ord(c) > 127: s += " " else: - s += c + s += chr(c) return s def _get_content(self, part, name, auto_decompress=True, auto_hex=True): diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 56410153..70979689 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")) -- cgit v1.2.3