From ae3f10fba648644a568dab3e21480580eb21e8a1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 9 May 2005 12:59:08 +0000 Subject: * more work on the native python apt interface --- doc/examples/depcache.py | 24 ++++++------------------ doc/examples/progress.py | 12 ++++++------ 2 files changed, 12 insertions(+), 24 deletions(-) (limited to 'doc') diff --git a/doc/examples/depcache.py b/doc/examples/depcache.py index 50dd7703..556c954b 100644 --- a/doc/examples/depcache.py +++ b/doc/examples/depcache.py @@ -1,29 +1,17 @@ #!/usr/bin/python # example how to deal with the depcache +import apt import apt_pkg import sys import copy +from progress import TextProgress -class MyProgress: - def __init__(self): - self.last = 0.0 - - def Update(self, percent): - if (self.last + 1.0) <= percent: - print "Progress: %s " % (percent) - self.last = percent - if percent >= 100: - self.last = 0.0 - - def Done(self): - self.last = 0.0 - print "Done!" # init apt_pkg.init() -progress = MyProgress() +progress = TextProgress() cache = apt_pkg.GetCache(progress) print "Available packages: %s " % cache.PackageCount @@ -32,10 +20,10 @@ print "example package iter: %s" % iter # get depcache print "\n\n depcache" -depcache = apt_pkg.GetDepCache(cache, progress) +depcache = apt_pkg.GetDepCache(cache) depcache.ReadPinFile() # init is needed after the creation/pin file reading -depcache.Init() +depcache.Init(progress) print "got a depcache: %s " % depcache print "Marked for install: %s " % depcache.InstCount @@ -78,7 +66,7 @@ print "Marking %s for keep" % iter.Name depcache.MarkKeep(iter) print "Install: %s " % depcache.InstCount -iter = cache["3dwm-server"] +iter = cache["synaptic"] print "\nMarking '%s' for install" % iter.Name depcache.MarkInstall(iter) print "Install: %s " % depcache.InstCount diff --git a/doc/examples/progress.py b/doc/examples/progress.py index 67d39c9c..d96b8916 100644 --- a/doc/examples/progress.py +++ b/doc/examples/progress.py @@ -1,11 +1,11 @@ -import apt_pkg +import apt import sys import time import string -class OpProgress: +class TextProgress(apt.OpProgress): def __init__(self): - self.last = 0.0 + self.last=0.0 def Update(self, percent): if (self.last + 1.0) <= percent: @@ -19,7 +19,7 @@ class OpProgress: print "\rDone " -class FetchProgress: +class TextFetchProgress(apt.FetchProgress): def __init__(self): pass @@ -40,7 +40,7 @@ class FetchProgress: #return False -class InstallProgress: +class TextInstallProgress(apt.InstallProgress): def __init__(self): pass def StartUpdate(self): @@ -52,7 +52,7 @@ class InstallProgress: time.sleep(0.1) -class CdromProgress: +class TextCdromProgress(apt.CdromProgress): def __init__(self): pass # update is called regularly so that the gui can be redrawn -- cgit v1.2.3