diff options
| author | Michael Vogt <egon@bottom> | 2006-12-19 11:50:52 +0100 |
|---|---|---|
| committer | Michael Vogt <egon@bottom> | 2006-12-19 11:50:52 +0100 |
| commit | 75da7640381be141209986156eba32825019add8 (patch) | |
| tree | 5aa439eeeb55331ca9e8d3245b0c387d8c58ca10 /apt | |
| parent | a38c71a5197429ccb1703d9b3c2d943be6017f7d (diff) | |
| parent | 3c393390f10b5ecfb3891fb89f199e2610d9246e (diff) | |
| download | python-apt-75da7640381be141209986156eba32825019add8.tar.gz | |
* merged from mainline
Diffstat (limited to 'apt')
| -rw-r--r-- | apt/progress.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/apt/progress.py b/apt/progress.py index 4119067c..5169adf7 100644 --- a/apt/progress.py +++ b/apt/progress.py @@ -19,7 +19,14 @@ # 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 class OpProgress(object): """ Abstract class to implement reporting on cache opening @@ -139,6 +146,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 +170,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 +197,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 |
