summaryrefslogtreecommitdiff
path: root/doc/source/examples/missing-deps.py
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2009-01-13 17:50:30 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2009-01-13 17:50:30 +0100
commit8b46b0c4bdfbaa07972311b1cf19616d5c5aff04 (patch)
tree59167b2b8c1d331bfebf072d5ba84dd154f0b373 /doc/source/examples/missing-deps.py
parent6c1711a80a8a7d011f4d5f49618ff396ad2f5722 (diff)
parent85839f4f241c99f9e4ebb0a6a8847a2d433f1160 (diff)
downloadpython-apt-8b46b0c4bdfbaa07972311b1cf19616d5c5aff04.tar.gz
merge from the debian experimental branch
Diffstat (limited to 'doc/source/examples/missing-deps.py')
-rw-r--r--doc/source/examples/missing-deps.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/doc/source/examples/missing-deps.py b/doc/source/examples/missing-deps.py
new file mode 100644
index 00000000..3ca16e45
--- /dev/null
+++ b/doc/source/examples/missing-deps.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+"""Check the archive for missing dependencies"""
+import apt_pkg
+
+
+def fmt_dep(dep):
+ """Format a Dependency object [of apt_pkg] as a string."""
+ ret = dep.TargetPkg.Name
+ if dep.TargetVer:
+ ret += " (%s %s)" % (dep.CompType, dep.TargetVer)
+ return ret
+
+
+def check_version(pkgver):
+ """Check the version of the package"""
+ missing = []
+
+ for or_group in pkgver.DependsList.get("Pre-Depends", []) + \
+ pkgver.DependsList.get("Depends", []):
+ if not any(dep.AllTargets() for dep in or_group):
+ # If none of the or-choices can be satisfied, add it to missing
+ missing.append(or_group)
+
+ if missing:
+ print "Package:", pkgver.ParentPkg.Name
+ print "Version:", pkgver.VerStr
+ print "Missing:",
+ print ", ".join(" | ".join(fmt_dep(dep) for dep in or_group)
+ for or_group in missing)
+ print
+
+
+def main():
+ """The main function."""
+ apt_pkg.InitConfig()
+ apt_pkg.InitSystem()
+
+ cache = apt_pkg.GetCache()
+
+ for pkg in sorted(cache.Packages, key=lambda pkg: pkg.Name):
+ # pkg is from a list of packages, sorted by name.
+ for version in pkg.VersionList:
+ # Check every version
+ for pfile, _ in version.FileList:
+ if (pfile.Origin == "Debian" and pfile.Component == "main" and
+ pfile.Archive == "unstable"):
+ # We only want packages from Debian unstable main.
+ check_version(version)
+ break
+
+if __name__ == "__main__":
+ main()