aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gaffney <agaffney@gentoo.org>2005-10-21 04:31:01 +0000
committerAndrew Gaffney <agaffney@gentoo.org>2005-10-21 04:31:01 +0000
commit6793d5c7dd9499fb43437ee400d8bc40757c7ec3 (patch)
tree097419f33c8e290adc26197387d83da25d35471c /src/GLIUtility.py
parentadd unpack progress to portage snapshot (diff)
downloadgli-6793d5c7dd9499fb43437ee400d8bc40757c7ec3.tar.gz
gli-6793d5c7dd9499fb43437ee400d8bc40757c7ec3.tar.bz2
gli-6793d5c7dd9499fb43437ee400d8bc40757c7ec3.zip
use read() instead of readlines() in spawn()
only update progress bar for whole percents git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/gli/trunk@982 f8877401-5920-0410-a79b-8e2d7e04ca0d
Diffstat (limited to 'src/GLIUtility.py')
-rw-r--r--src/GLIUtility.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/GLIUtility.py b/src/GLIUtility.py
index 9f92915..2ae5050 100644
--- a/src/GLIUtility.py
+++ b/src/GLIUtility.py
@@ -320,27 +320,37 @@ def spawn(cmd, quiet=False, logfile=None, display_on_tty8=False, chroot=None, ap
# read a line from the pipe and loop until
# pipe is empty
- data = ro_pipe.readline()
+# data = ro_pipe.readline()
seenlines = 0
+ last_percent = 0
+
+ while 1:
+ data = ro_pipe.read(2048)
+ if not data: break
- while data:
if logfile:
fd_logfile.write(data)
# fd_logfile.flush()
if display_on_tty8:
fd_tty.write(data)
-# fd_tty.flush()
+ fd_tty.flush()
if return_output:
- output = output + data
+ output += data
if linecount and cc:
- seenlines += 1
- if not seenlines % 20:
- cc.addNotification("progress", (float(seenlines) / linecount, status_message))
-
- data = ro_pipe.readline()
+ lastpos = -1
+ while 1:
+ lastpos = data.find("\n", lastpos + 1)
+ if lastpos == -1: break
+ seenlines += 1
+ percent = float(seenlines) / linecount
+ if int(percent * 100) > last_percent:
+ last_percent = int(percent * 100)
+ cc.addNotification("progress", (percent, status_message))
+
+# data = ro_pipe.readline()
# close the file descriptors
if logfile: fd_logfile.close()