summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt/cache.py10
-rw-r--r--apt/debfile.py19
-rw-r--r--debian/changelog6
-rw-r--r--tests/test_debfile.py12
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 <mvo@debian.org> 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 <samuel@slbdata.se>")
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