summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2015-05-07 17:20:13 +0200
committerMichael Vogt <mvo@ubuntu.com>2015-05-07 17:20:13 +0200
commite03ec63ce07e597c6f29edc5121a24f874cf6aaa (patch)
tree459afa6eaf54b46ce079957198a358554ab74fc4 /doc
parent778954e0e051aaf1c263a2418156a6f82213386a (diff)
downloadpython-apt-e03ec63ce07e597c6f29edc5121a24f874cf6aaa.tar.gz
Update doc/example/action.py for py3 and latest API
closes: #782335
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/action.py118
-rw-r--r--doc/examples/progress.py30
2 files changed, 75 insertions, 73 deletions
diff --git a/doc/examples/action.py b/doc/examples/action.py
index 41b55144..b395adc6 100644
--- a/doc/examples/action.py
+++ b/doc/examples/action.py
@@ -1,8 +1,12 @@
#!/usr/bin/python
-# example how to deal with the depcache
+#
+# LOW LEVEL example how to deal with the depcache
+#
+# you probably do not want to use this low level code and use
+# the high level "apt" interface instead that can do all this
+# but with a nicer API
import apt_pkg
-import sys
from apt.progress.text import OpProgress
from progress import TextFetchProgress
@@ -11,100 +15,98 @@ apt_pkg.init()
progress = OpProgress()
cache = apt_pkg.Cache(progress)
-print "Available packages: %s " % cache.package_count
+print("Available packages: %s " % cache.package_count)
-print "Fetching"
+print("Fetching")
progress = TextFetchProgress()
-cache.update(progress)
-
-print "Exiting"
-sys.exit(0)
+source = apt_pkg.SourceList()
+cache.update(progress, source)
iter = cache["base-config"]
-print "example package iter: %s" % iter
+print("example package iter: %s" % iter)
# get depcache
-print "\n\n depcache"
-depcache = apt_pkg.DepCache(cache, progress)
-depcache.read_pin_file()
-print "got a depcache: %s " % depcache
-print "Marked for install: %s " % depcache.inst_count
+print("\n\n depcache")
+depcache = apt_pkg.DepCache(cache)
+depcache.read_pinfile()
+print("got a depcache: %s " % depcache)
+print("Marked for install: %s " % depcache.inst_count)
-print "\n\n Reinit"
+print("\n\n Reinit")
depcache.init(progress)
#sys.exit()
# get a canidate version
ver = depcache.get_candidate_ver(iter)
-print "Candidate version: %s " % ver
+print("Candidate version: %s " % ver)
-print "\n\nQuerry interface"
-print "%s.is_upgradable(): %s" % (iter.name, depcache.is_upgradable(iter))
+print("\n\nQuerry interface")
+print("%s.is_upgradable(): %s" % (iter.name, depcache.is_upgradable(iter)))
-print "\nMarking interface"
-print "Marking '%s' for install" % iter.name
+print("\nMarking interface")
+print("Marking '%s' for install" % iter.name)
depcache.mark_install(iter)
-print "Install count: %s " % depcache.inst_count
-print "%s.marked_install(): %s" % (iter.name, depcache.marked_install(iter))
-print "%s.marked_upgrade(): %s" % (iter.name, depcache.marked_upgrade(iter))
-print "%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter))
+print("Install count: %s " % depcache.inst_count)
+print("%s.marked_install(): %s" % (iter.name, depcache.marked_install(iter)))
+print("%s.marked_upgrade(): %s" % (iter.name, depcache.marked_upgrade(iter)))
+print("%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter)))
-print "Marking %s for delete" % iter.name
+print("Marking %s for delete" % iter.name)
depcache.mark_delete(iter)
-print "del_count: %s " % depcache.del_count
-print "%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter))
+print("del_count: %s " % depcache.del_count)
+print("%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter)))
-iter = cache["3dchess"]
-print "\nMarking '%s' for install" % iter.name
+iter = cache["apt"]
+print("\nMarking '%s' for install" % iter.name)
depcache.mark_install(iter)
-print "Install count: %s " % depcache.inst_count
-print "%s.marked_install(): %s" % (iter.name, depcache.marked_install(iter))
-print "%s.marked_upgrade(): %s" % (iter.name, depcache.marked_upgrade(iter))
-print "%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter))
+print("Install count: %s " % depcache.inst_count)
+print("%s.marked_install(): %s" % (iter.name, depcache.marked_install(iter)))
+print("%s.marked_upgrade(): %s" % (iter.name, depcache.marked_upgrade(iter)))
+print("%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter)))
-print "Marking %s for keep" % iter.name
+print("Marking %s for keep" % iter.name)
depcache.mark_keep(iter)
-print "Install: %s " % depcache.inst_count
+print("Install: %s " % depcache.inst_count)
-iter = cache["3dwm-server"]
-print "\nMarking '%s' for install" % iter.name
+iter = cache["python-apt"]
+print("\nMarking '%s' for install" % iter.name)
depcache.mark_install(iter)
-print "Install: %s " % depcache.inst_count
-print "Broken count: %s" % depcache.broken_count
-print "fix_broken() "
+print("Install: %s " % depcache.inst_count)
+print("Broken count: %s" % depcache.broken_count)
+print("fix_broken() ")
depcache.fix_broken()
-print "Broken count: %s" % depcache.broken_count
+print("Broken count: %s" % depcache.broken_count)
-print "\nPerforming upgrade"
+print("\nPerforming upgrade")
depcache.upgrade()
-print "Keep: %s " % depcache.keep_count
-print "Install: %s " % depcache.inst_count
-print "Delete: %s " % depcache.del_count
-print "usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size)
-print "deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size)
+print("Keep: %s " % depcache.keep_count)
+print("Install: %s " % depcache.inst_count)
+print("Delete: %s " % depcache.del_count)
+print("usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size))
+print("deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size))
for pkg in cache.packages:
if pkg.current_ver is not None and not depcache.marked_install(pkg) \
and depcache.is_upgradable(pkg):
- print "upgrade didn't upgrade (kept): %s" % pkg.name
+ print("upgrade didn't upgrade (kept): %s" % pkg.name)
-print "\nPerforming Distupgrade"
+print("\nPerforming Distupgrade")
depcache.upgrade(True)
-print "Keep: %s " % depcache.keep_count
-print "Install: %s " % depcache.inst_count
-print "Delete: %s " % depcache.del_count
-print "usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size)
-print "deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size)
+print("Keep: %s " % depcache.keep_count)
+print("Install: %s " % depcache.inst_count)
+print("Delete: %s " % depcache.del_count)
+print("usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size))
+print("deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size))
# overview about what would happen
for pkg in cache.packages:
if depcache.marked_install(pkg):
if pkg.current_ver is not None:
- print "Marked upgrade: %s " % pkg.name
+ print("Marked upgrade: %s " % pkg.name)
else:
- print "Marked install: %s" % pkg.name
+ print("Marked install: %s" % pkg.name)
elif depcache.marked_delete(pkg):
- print "Marked delete: %s" % pkg.name
+ print("Marked delete: %s" % pkg.name)
elif depcache.marked_keep(pkg):
- print "Marked keep: %s" % pkg.name
+ print("Marked keep: %s" % pkg.name)
diff --git a/doc/examples/progress.py b/doc/examples/progress.py
index 32dac330..a273eb24 100644
--- a/doc/examples/progress.py
+++ b/doc/examples/progress.py
@@ -22,7 +22,7 @@ class TextProgress(apt.progress.base.OpProgress):
def done(self):
self.last = 0.0
- print "\rDone "
+ print("\rDone ")
class TextFetchProgress(apt.progress.base.AcquireProgress):
@@ -37,25 +37,25 @@ class TextFetchProgress(apt.progress.base.AcquireProgress):
pass
def fail(self, item):
- print 'fail', item
+ print('fail', item)
def fetch(self, item):
- print 'fetch', item
+ print('fetch', item)
def ims_hit(self, item):
- print 'ims_hit', item
+ print('ims_hit', item)
def pulse(self, owner):
- print "pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (
+ print("pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (
apt_pkg.size_to_str(self.current_cps),
apt_pkg.size_to_str(self.current_bytes),
apt_pkg.size_to_str(self.total_bytes),
self.current_items,
- self.total_items)
+ self.total_items))
return True
def media_change(self, medium, drive):
- print "Please insert medium %s in drive %s" % (medium, drive)
+ print("Please insert medium %s in drive %s" % (medium, drive))
sys.stdin.readline()
#return False
@@ -67,13 +67,13 @@ class TextInstallProgress(apt.progress.base.InstallProgress):
pass
def start_update(self):
- print "start_update"
+ print("start_update")
def finish_update(self):
- print "finish_update"
+ print("finish_update")
def status_change(self, pkg, percent, status):
- print "[%s] %s: %s" % (percent, pkg, status)
+ print("[%s] %s: %s" % (percent, pkg, status))
def update_interface(self):
apt.progress.base.InstallProgress.update_interface(self)
@@ -91,17 +91,17 @@ class TextCdromProgress(apt.progress.base.CdromProgress):
def update(self, text, step):
# check if we actually have some text to display
if text != "":
- print "Update: %s %s" % (text.strip(), step)
+ print("Update: %s %s" % (text.strip(), step))
def ask_cdrom_name(self):
- print "Please enter cd-name: ",
+ sys.stdout.write("Please enter cd-name: ")
cd_name = sys.stdin.readline()
return (True, cd_name.strip())
def change_cdrom(self):
- print "Please insert cdrom and press <ENTER>"
+ print("Please insert cdrom and press <ENTER>")
answer = sys.stdin.readline()
- print answer
+ print(answer)
return True
@@ -115,4 +115,4 @@ if __name__ == "__main__":
res = c.commit(TextFetchProgress(), TextInstallProgress())
- print res
+ print(res)