diff options
Diffstat (limited to 'apt/progress.py')
| -rw-r--r-- | apt/progress.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/apt/progress.py b/apt/progress.py index 4119067c..bb1bce35 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,16 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import sys, apt_pkg, os, fcntl, string, re +import sys +import os +import re +import fcntl +import string +from errno import * +import select +import apt_pkg + +import apt class OpProgress(object): """ Abstract class to implement reporting on cache opening @@ -139,6 +148,7 @@ class InstallProgress(DumbInstallProgress): """ def __init__(self): DumbInstallProgress.__init__(self) + self.selectTimeout = 0.1 (read, write) = os.pipe() self.writefd=write self.statusfd = os.fdopen(read, "r") @@ -162,12 +172,17 @@ class InstallProgress(DumbInstallProgress): self.read += os.read(self.statusfd.fileno(),1) except OSError, (errno,errstr): # resource temporarly unavailable is ignored - if errno != 11: + if errno != EAGAIN and errnor != EWOULDBLOCK: print errstr if self.read.endswith("\n"): s = self.read #print s - (status, pkg, percent, status_str) = string.split(s, ":") + try: + (status, pkg, percent, status_str) = string.split(s, ":",3) + except ValueError, e: + # silently ignore lines that can't be parsed + self.read = "" + return #print "percent: %s %s" % (pkg, float(percent)/100.0) if status == "pmerror": self.error(pkg,status_str) @@ -184,22 +199,22 @@ class InstallProgress(DumbInstallProgress): self.percent = float(percent) self.status = string.strip(status_str) self.read = "" - def fork(self): return os.fork() def waitChild(self): while True: + select.select([self.statusfd],[],[], self.selectTimeout) + self.updateInterface() (pid, res) = os.waitpid(self.child_pid,os.WNOHANG) if pid == self.child_pid: break - self.updateInterface() return os.WEXITSTATUS(res) def run(self, pm): pid = self.fork() if pid == 0: # child res = pm.DoInstall(self.writefd) - sys.exit(res) + os._exit(res) self.child_pid = pid res = self.waitChild() return res |
