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 / dependant-pkgs.py < prev    next >
Encoding:
Python Source  |  2006-03-02  |  786 b   |  37 lines

  1. #!/usr/bin/env python
  2.  
  3. import apt
  4. import sys
  5.  
  6. pkgs = set()
  7. cache = apt.Cache()
  8. for pkg in cache:
  9.     candver = cache._depcache.GetCandidateVer(pkg._pkg)
  10.     if candver == None:
  11.         continue
  12.     dependslist = candver.DependsList
  13.     for dep in dependslist.keys():
  14.         # get the list of each dependency object
  15.         for depVerList in dependslist[dep]:
  16.             for z in depVerList:
  17.                 # get all TargetVersions of
  18.                 # the dependency object
  19.                 for tpkg in z.AllTargets():
  20.                     if sys.argv[1] == tpkg.ParentPkg.Name:
  21.                         pkgs.add(pkg.name)
  22.  
  23. main = set()
  24. universe = set()
  25. for pkg in pkgs:
  26.     if "universe" in cache[pkg].section:
  27.         universe.add(cache[pkg].sourcePackageName)
  28.     else:
  29.         main.add(cache[pkg].sourcePackageName)
  30.  
  31. print "main:"        
  32. print "\n".join(main)
  33. print
  34.  
  35. print "universe:"        
  36. print "\n".join(universe)
  37.