From e608d6106a75a678fe121afd8020073b9ba80836 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 20 Oct 2005 10:08:11 +0000 Subject: * merged with the progress reporting code Patches applied: * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--base-0 tag of michael.vogt@ubuntu.com--2005/python-apt--mvo--0--patch-43 * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--patch-1 * support the apt--progress-reporting--0 branch (using "InstallProgress.statusfd) * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--patch-2 * support for update reporting via vte/progress bars added, including a evil "pass-me-my-file-descriptor" hack * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--patch-3 * merged with python-apt--mvo * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--patch-4 * merged from python-apt--mvo * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--patch-5 * better support new python-apt, added example for gui-inst with support for VTE_PTY_KEEP_FD * michael.vogt@ubuntu.com--2005/python-apt--progress-reporting--0--patch-6 * removed the fdsend stuff again, libvte will be patched instead --- doc/examples/gui-inst.py | 54 ++++++++++++++++++++++++++++++++++++++++-------- doc/examples/inst.py | 16 ++++++++++++++ 2 files changed, 61 insertions(+), 9 deletions(-) mode change 100644 => 100755 doc/examples/gui-inst.py (limited to 'doc/examples') diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py old mode 100644 new mode 100755 index b2f64e91..38417e10 --- a/doc/examples/gui-inst.py +++ b/doc/examples/gui-inst.py @@ -3,8 +3,10 @@ # see also gnome bug: #169201 import apt_pkg -import sys, os +import sys, os, fcntl import copy +import string +import fcntl import pygtk pygtk.require('2.0') @@ -28,13 +30,14 @@ class GuiFetchProgress(gtk.Window, FetchProgress): self.vbox.pack_start(self.label) self.resize(300,100) def start(self): - self.progress.set_fraction(0) + print "start" + self.progress.set_fraction(0.0) self.show() def stop(self): self.hide() def pulse(self): self.label.set_text("Speed: %s/s" % apt_pkg.SizeToStr(self.currentCPS)) - self.progress.set_fraction(self.currentBytes/self.totalBytes) + #self.progressbar.set_fraction(self.currentBytes/self.totalBytes) while gtk.events_pending(): gtk.main_iteration() @@ -42,21 +45,54 @@ class TermInstallProgress(InstallProgress, gtk.Window): def __init__(self): gtk.Window.__init__(self) self.show() + box = gtk.VBox() + box.show() + self.add(box) self.term = vte.Terminal() self.term.show() - self.add(self.term) - def start(self): - self.progress.set_fraction(0) + box.pack_start(self.term) + self.progressbar = gtk.ProgressBar() + self.progressbar.show() + box.pack_start(self.progressbar) + + (read, write) = os.pipe() + self.writefd=write + self.status = os.fdopen(read, "r") + fcntl.fcntl(self.status.fileno(), fcntl.F_SETFL,os.O_NONBLOCK) + print "read-fd: %s" % self.status.fileno() + print "write-fd: %s" % self.writefd + self.read = "" + + def startUpdate(self): + print "start" self.show() - def stop(self): - self.hide() def updateInterface(self): + if self.status != None: + try: + self.read += os.read(self.status.fileno(),1) + except OSError, (errno,errstr): + # resource temporarly unavailable is ignored + if errno != 11: + print errstr + if self.read.endswith("\n"): + s = self.read + print s + (status, pkg, percent, status_str) = string.split(s, ":") + print "percent: %s %s" % (pkg, float(percent)/100.0) + self.progressbar.set_fraction(float(percent)/100.0) + self.progressbar.set_text(string.strip(status_str)) + self.read = "" while gtk.events_pending(): gtk.main_iteration() def finishUpdate(self): sys.stdin.readline() def fork(self): - return self.term.forkpty() + print "fork" + env = ["VTE_PTY_KEEP_FD=%s"%self.writefd] + print env + pid = self.term.forkpty(envv=env) + print "After fork: %s " % pid + return pid # init diff --git a/doc/examples/inst.py b/doc/examples/inst.py index b25cf542..fe5ec8e3 100644 --- a/doc/examples/inst.py +++ b/doc/examples/inst.py @@ -1,6 +1,7 @@ #!/usr/bin/python # example how to deal with the depcache +import apt import apt_pkg import sys, os import copy @@ -8,6 +9,21 @@ import copy from progress import TextFetchProgress, TextInstallProgress from apt.progress import OpTextProgress +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() -- cgit v1.2.3