home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / checkstate.py < prev    next >
Encoding:
Python Source  |  2006-03-02  |  867 b   |  37 lines

  1. #!/usr/bin/python
  2. #
  3. #
  4. # this example is not usefull to find out about updated, upgradable packages
  5. # use the depcache.py example for it (because a pkgPolicy is not used here)
  6. #
  7.  
  8. import apt_pkg
  9. apt_pkg.init()
  10.  
  11. cache = apt_pkg.GetCache()
  12. packages = cache.Packages
  13.  
  14. uninstalled, updated, upgradable = {}, {}, {}
  15.  
  16. for package in packages:
  17.     versions = package.VersionList
  18.     if not versions:
  19.         continue
  20.     version = versions[0]
  21.     for other_version in versions:
  22.         if apt_pkg.VersionCompare(version.VerStr, other_version.VerStr)<0:
  23.             version = other_version
  24.     if package.CurrentVer:
  25.         current = package.CurrentVer
  26.         if apt_pkg.VersionCompare(current.VerStr, version.VerStr)<0:
  27.             upgradable[package.Name] = version
  28.             break
  29.         else:
  30.             updated[package.Name] = current
  31.     else:
  32.         uninstalled[package.Name] = version
  33.  
  34.  
  35. for l in (uninstalled, updated, upgradable):
  36.     print l.items()[0]
  37.