summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-06-29 11:41:33 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-06-29 11:41:33 +0200
commit5a6c646ceffab7ce58106eccdccf884b6d332d58 (patch)
tree0c8688b9adbea946ca41757e0c446d8374e06657
parent340f6a3d54f5705801267f365fb08b5d20228fe6 (diff)
parent508f1ddb5b6a0cc69655e39dbd59fe3466173a84 (diff)
downloadpython-apt-5a6c646ceffab7ce58106eccdccf884b6d332d58.tar.gz
* apt/cache.py:
- add new "dpkg_journal_dirty" property that can be used to detect a interrupted dpkg (the famous "E: dpkg was interrupted, you must manually run 'dpkg --configure -a'")
-rw-r--r--apt/cache.py15
-rw-r--r--debian/changelog4
-rw-r--r--tests/test_apt_cache.py26
3 files changed, 45 insertions, 0 deletions
diff --git a/apt/cache.py b/apt/cache.py
index 3679e4ba..3962bb4f 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -19,6 +19,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
+import fnmatch
import os
import weakref
@@ -455,6 +456,20 @@ class Cache(object):
return apt_pkg.ActionGroup(self._depcache)
@property
+ def dpkg_journal_dirty(self):
+ """Return True if the dpkg was interrupted
+
+ All dpkg operations will fail until this is fixed, the action to
+ fix the system if dpkg got interrupted is to run
+ 'dpkg --configure -a' as root.
+ """
+ dpkg_status_dir = os.path.dirname(apt_pkg.Config.find_file("Dir::State::status"))
+ for f in os.listdir(os.path.join(dpkg_status_dir, "updates")):
+ if fnmatch.fnmatch(f, "[0-9]*"):
+ return True
+ return False
+
+ @property
def broken_count(self):
"""Return the number of packages with broken dependencies."""
return self._depcache.broken_count
diff --git a/debian/changelog b/debian/changelog
index b7bb3ad0..b1c7c1b5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -11,6 +11,10 @@ python-apt (0.7.96) UNRELEASED; urgency=low
- do not fail on non-digits in the version number
* utils/get_debian_mirrors.py:
- ignore mirrors without a county
+ * apt/cache.py:
+ - add new "dpkg_journal_dirty" property that can be used to
+ detect a interrupted dpkg (the famous
+ "E: dpkg was interrupted, you must manually run 'dpkg --configure -a'")
[ Martin Pitt ]
* tests/test_apt_cache.py: Test accessing the record of all packages during
diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py
index a00fa08b..b27ed778 100644
--- a/tests/test_apt_cache.py
+++ b/tests/test_apt_cache.py
@@ -9,6 +9,9 @@
import unittest
import apt
+import apt_pkg
+import os
+import tempfile
class TestAptCache(unittest.TestCase):
@@ -39,5 +42,28 @@ class TestAptCache(unittest.TestCase):
self.assert_(len(r['Description']) > 0)
self.assert_(str(r).startswith('Package: %s\n' % pkg.name))
+ def test_dpkg_journal_dirty(self):
+ # backup old value
+ old_status = apt_pkg.Config.find_file("Dir::State::status")
+ # create tmp env
+ tmpdir = tempfile.mkdtemp()
+ dpkg_dir = os.path.join(tmpdir,"var","lib","dpkg")
+ os.makedirs(os.path.join(dpkg_dir,"updates"))
+ open(os.path.join(dpkg_dir,"status"), "w")
+ apt_pkg.Config.set("Dir::State::status",
+ os.path.join(dpkg_dir,"status"))
+ cache = apt.Cache()
+ # test empty
+ self.assertFalse(cache.dpkg_journal_dirty)
+ # that is ok, only [0-9] are dpkg jounral entries
+ open(os.path.join(dpkg_dir,"updates","xxx"), "w")
+ self.assertFalse(cache.dpkg_journal_dirty)
+ # that is a dirty journal
+ open(os.path.join(dpkg_dir,"updates","000"), "w")
+ self.assertTrue(cache.dpkg_journal_dirty)
+ # reset config value
+ apt_pkg.Config.set("Dir::State::status", old_status)
+
+
if __name__ == "__main__":
unittest.main()