diff options
| -rwxr-xr-x[-rw-r--r--] | doc/examples/gui-inst.py | 54 | ||||
| -rw-r--r-- | doc/examples/inst.py | 16 | ||||
| -rw-r--r-- | python/makefile | 1 | ||||
| -rw-r--r-- | python/progress.cc | 9 | ||||
| -rw-r--r-- | setup.py | 1 |
5 files changed, 70 insertions, 11 deletions
diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py index b2f64e91..38417e10 100644..100755 --- 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() diff --git a/python/makefile b/python/makefile index 273096a7..16bfcd88 100644 --- a/python/makefile +++ b/python/makefile @@ -22,3 +22,4 @@ LIB_MAKES = apt-inst/makefile APT_INST_SRC = apt_instmodule.cc tar.cc generic.cc SOURCE := $(APT_INST_SRC) include $(PYTHON_H) + diff --git a/python/progress.cc b/python/progress.cc index f79090f7..fb56ea87 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -11,6 +11,7 @@ #include <sys/wait.h> #include "progress.h" + // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, PyObject *arglist, @@ -220,7 +221,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) return pkgPackageManager::Failed; } if(!PyArg_Parse(result, "i", &child_id) ) - std::cerr << "result could not be parsed?"<< std::endl; + std::cerr << "custom fork() result could not be parsed?"<< std::endl; //std::cerr << "got: " << child_id << std::endl; } else { //std::cerr << "using build-in fork()" << std::endl; @@ -235,10 +236,14 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) } #endif if (child_id == 0) { - res = pm->DoInstall(); + PyObject *v = PyObject_GetAttrString(callbackInst, "writefd"); + int fd = PyObject_AsFileDescriptor(v); + cout << "got fd: " << fd << endl; + res = pm->DoInstall(fd); _exit(res); } + StartUpdate(); while (waitpid(child_id, &ret, WNOHANG) == 0) UpdateInterface(); @@ -20,6 +20,7 @@ for i in range(0,len(files)): apt_inst = Extension("apt_inst", files, libraries=["apt-pkg","apt-inst"]); + setup(name="python-apt", version="0.6.13", description="Python bindings for APT", |
