home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / missing-deps.py < prev    next >
Encoding:
Python Source  |  2009-03-30  |  1.6 KB  |  53 lines

  1. #!/usr/bin/python
  2. """Check the archive for missing dependencies"""
  3. import apt_pkg
  4.  
  5.  
  6. def fmt_dep(dep):
  7.     """Format a Dependency object [of apt_pkg] as a string."""
  8.     ret = dep.TargetPkg.Name
  9.     if dep.TargetVer:
  10.         ret += " (%s %s)" % (dep.CompType, dep.TargetVer)
  11.     return ret
  12.  
  13.  
  14. def check_version(pkgver):
  15.     """Check the version of the package"""
  16.     missing = []
  17.  
  18.     for or_group in pkgver.DependsList.get("Pre-Depends", []) + \
  19.                     pkgver.DependsList.get("Depends", []):
  20.         if not any(dep.AllTargets() for dep in or_group):
  21.             # If none of the or-choices can be satisfied, add it to missing
  22.             missing.append(or_group)
  23.  
  24.     if missing:
  25.         print "Package:", pkgver.ParentPkg.Name
  26.         print "Version:", pkgver.VerStr
  27.         print "Missing:",
  28.         print ", ".join(" | ".join(fmt_dep(dep) for dep in or_group)
  29.                         for or_group in missing)
  30.         print
  31.  
  32.  
  33. def main():
  34.     """The main function."""
  35.     apt_pkg.InitConfig()
  36.     apt_pkg.InitSystem()
  37.  
  38.     cache = apt_pkg.GetCache()
  39.  
  40.     for pkg in sorted(cache.Packages, key=lambda pkg: pkg.Name):
  41.         # pkg is from a list of packages, sorted by name.
  42.         for version in pkg.VersionList:
  43.             # Check every version
  44.             for pfile, _ in version.FileList:
  45.                 if (pfile.Origin == "Debian" and pfile.Component == "main" and
  46.                     pfile.Archive == "unstable"):
  47.                     # We only want packages from Debian unstable main.
  48.                     check_version(version)
  49.                     break
  50.  
  51. if __name__ == "__main__":
  52.     main()
  53.