/usr/share/doc/python-apt/examples/depcache.py is in python-apt-doc 0.8.3ubuntu7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #!/usr/bin/python
# example how to deal with the depcache
import apt_pkg
from progress import TextProgress
# init
apt_pkg.init()
progress = TextProgress()
cache = apt_pkg.Cache(progress)
print "Available packages: %s " % cache.PackageCount
iter = cache["base-config"]
print "example package iter: %s" % iter
# get depcache
print "\n\n depcache"
depcache = apt_pkg.DepCache(cache)
depcache.ReadPinFile()
# init is needed after the creation/pin file reading
depcache.Init(progress)
print "got a depcache: %s " % depcache
print "Marked for install: %s " % depcache.InstCount
print "\n\n Reinit"
depcache.Init(progress)
#sys.exit()
# get a canidate version
ver= depcache.GetCandidateVer(iter)
print "Candidate version: %s " % ver
print "\n\nQuerry interface"
print "%s.IsUpgradable(): %s" % (iter.Name, depcache.IsUpgradable(iter))
print "\nMarking interface"
print "Marking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
print "Install count: %s " % depcache.InstCount
print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter))
print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter))
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
print "Marking %s for delete" % iter.Name
depcache.MarkDelete(iter)
print "DelCount: %s " % depcache.DelCount
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
iter = cache["3dchess"]
print "\nMarking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
print "Install count: %s " % depcache.InstCount
print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter))
print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter))
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
print "Marking %s for keep" % iter.Name
depcache.MarkKeep(iter)
print "Install: %s " % depcache.InstCount
iter = cache["synaptic"]
print "\nMarking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
print "Install: %s " % depcache.InstCount
print "Broken count: %s" % depcache.BrokenCount
print "FixBroken() "
depcache.FixBroken()
print "Broken count: %s" % depcache.BrokenCount
print "\nPerforming Upgrade"
depcache.Upgrade()
print "Keep: %s " % depcache.KeepCount
print "Install: %s " % depcache.InstCount
print "Delete: %s " % depcache.DelCount
print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize)
print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize)
for pkg in cache.Packages:
if pkg.CurrentVer is not None and not depcache.MarkedInstall(pkg) \
and depcache.IsUpgradable(pkg):
print "Upgrade didn't upgrade (kept): %s" % pkg.Name
print "\nPerforming DistUpgrade"
depcache.Upgrade(True)
print "Keep: %s " % depcache.KeepCount
print "Install: %s " % depcache.InstCount
print "Delete: %s " % depcache.DelCount
print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize)
print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize)
# overview about what would happen
for pkg in cache.Packages:
if depcache.MarkedInstall(pkg):
if pkg.CurrentVer is not None:
print "Marked upgrade: %s " % pkg.Name
else:
print "Marked install: %s" % pkg.Name
elif depcache.MarkedDelete(pkg):
print "Marked delete: %s" % pkg.Name
elif depcache.MarkedKeep(pkg):
print "Marked keep: %s" % pkg.Name
|