diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-12-06 21:59:07 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-12-06 21:59:07 +0000 |
| commit | b4141dda949890eaa50f0097b6fc6baeb3c489ac (patch) | |
| tree | e26442f8fbd08144d7bc69fa50e29027b1d1b576 /doc | |
| parent | 91c285d060448d7053f65ca5909784ae9273e6c8 (diff) | |
| download | python-apt-b4141dda949890eaa50f0097b6fc6baeb3c489ac.tar.gz | |
* apt.progress.InstallProgress class improved
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/examples/inst.py | 63 |
1 files changed, 22 insertions, 41 deletions
diff --git a/doc/examples/inst.py b/doc/examples/inst.py index fe5ec8e3..66b61c54 100644 --- a/doc/examples/inst.py +++ b/doc/examples/inst.py @@ -2,60 +2,41 @@ # example how to deal with the depcache import apt -import apt_pkg import sys, os import copy +import time -from progress import TextFetchProgress, TextInstallProgress -from apt.progress import OpTextProgress +from apt.progress import InstallProgress class TextInstallProgress(InstallProgress): def __init__(self): - InstallProgress.__init__(self) - self.status = None - def StartUpdate(self): - print "StartUpdate: %s" % self.statusfd - self.status = os.fdopen(self.statusfd, "r") - print self.status - def UpdateInterface(self): - if self.status != None: - s = self.status.readline() - if s: - print s - def FinishUpdate(self): - self.status.close() - -# init -apt_pkg.init() - -progress = OpTextProgress() -cache = apt_pkg.GetCache(progress) -print "Available packages: %s " % cache.PackageCount - -# get depcache -depcache = apt_pkg.GetDepCache(cache) -depcache.ReadPinFile() -depcache.Init(progress) - -# do something -fprogress = TextFetchProgress() + apt.progress.InstallProgress.__init__(self) + self.last = 0.0 + def updateInterface(self): + InstallProgress.updateInterface(self) + if self.last >= self.percent: + return + sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status)) + sys.stdout.flush() + self.last = self.percent + +cache = apt.Cache(apt.progress.OpTextProgress()) + +fprogress = apt.progress.TextFetchProgress() iprogress = TextInstallProgress() -# can be used to set a custom fork method (like vte.Terminal.forkpty) -#iprogress.fork = os.fork - -iter = cache["base-config"] -print "\n%s"%iter +pkg = cache["base-config"] # install or remove, the importend thing is to keep us busy :) -if iter.CurrentVer == None: - depcache.MarkInstall(iter) +if pkg.isInstalled: + print "Going to delete %s" % pkg.name + pkg.markDelete() else: - depcache.MarkDelete(iter) -res = depcache.Commit(fprogress, iprogress) + print "Going to install %s" % pkg.name + pkg.markInstall() +res = cache.commit(fprogress, iprogress) print res -print "Exiting" sys.exit(0) |
