summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-06-20 21:26:23 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-06-20 21:26:23 +0000
commitc25600f6cfb209dde14fbfc17aaef78519411a30 (patch)
treefb9e5b57e2404b76e568689b7d719461d5f10e90 /tests
parent33c18310943c8ee582fe57b1295e753f417d5eb8 (diff)
downloadpython-apt-c25600f6cfb209dde14fbfc17aaef78519411a30.tar.gz
* added support for the pkgProblemResolver()
Diffstat (limited to 'tests')
-rw-r--r--tests/apt-test.py7
-rw-r--r--tests/pkgproblemresolver.py69
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/apt-test.py b/tests/apt-test.py
index 4e41ae00..6ae9f702 100644
--- a/tests/apt-test.py
+++ b/tests/apt-test.py
@@ -4,4 +4,11 @@ if __name__ == "__main__":
progress = apt.progress.OpTextProgress()
cache = apt.Cache(progress)
print cache
+ for name in cache.keys():
+ pkg = cache[name]
+ if pkg.IsUpgradable():
+ pkg.MarkInstall()
+ for pkg in cache.GetChanges():
+ print pkg.Name()
+ print "Broken: %s " % cache._depcache.BrokenCount
diff --git a/tests/pkgproblemresolver.py b/tests/pkgproblemresolver.py
new file mode 100644
index 00000000..27747e43
--- /dev/null
+++ b/tests/pkgproblemresolver.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python2.4
+#
+# Test for the DepCache code
+#
+
+import apt_pkg
+import sys
+
+def main():
+ apt_pkg.init()
+ cache = apt_pkg.GetCache()
+ depcache = apt_pkg.GetDepCache(cache)
+ depcache.Init()
+ i=0
+ all=cache.PackageCount
+ print "Running DepCache test on all packages"
+ print "(trying to install each and then mark it keep again):"
+ # first, get all pkgs
+ for pkg in cache.Packages:
+ i += 1
+ x = pkg.Name
+ # then get each version
+ ver =depcache.GetCandidateVer(pkg)
+ if ver != None:
+ depcache.MarkInstall(pkg)
+ if depcache.BrokenCount > 0:
+ fixer = apt_pkg.GetPkgProblemResolver(depcache)
+ fixer.Clear(pkg)
+ fixer.Protect(pkg)
+ # we first try to resolve the problem
+ # with the package that should be installed
+ # protected
+ try:
+ fixer.Resolve(True)
+ except SystemError:
+ # the pkg seems to be broken, the
+ # returns a exception
+ fixer.Clear(pkg)
+ fixer.Resolve(True)
+ if not depcache.MarkedInstall(pkg):
+ print "broken in archive: %s " % pkg.Name
+ fixer = None
+ if depcache.InstCount == 0:
+ if depcache.IsUpgradable(pkg):
+ print "Error marking %s for install" % x
+ for p in cache.Packages:
+ if depcache.MarkedInstall(p) or depcache.MarkedUpgrade(p):
+ depcache.MarkKeep(p)
+ if depcache.InstCount != 0:
+ print "Error undoing the selection for %s" % x
+ print "\r%i/%i=%.3f%% " % (i,all,(float(i)/float(all)*100)),
+
+ print
+ print "Trying Upgrade:"
+ depcache.Upgrade()
+ print "To install: %s " % depcache.InstCount
+ print "To remove: %s " % depcache.DelCount
+ print "Kept back: %s " % depcache.KeepCount
+
+ print "Trying DistUpgrade:"
+ depcache.Upgrade(True)
+ print "To install: %s " % depcache.InstCount
+ print "To remove: %s " % depcache.DelCount
+ print "Kept back: %s " % depcache.KeepCount
+
+
+if __name__ == "__main__":
+ main()
+ sys.exit(0)