summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-16 19:43:38 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-16 19:43:38 +0200
commitc8f2e068538dd54206669394507a52115ce9a621 (patch)
tree181d62ded46be7d7addea6f12a93b8f1cd6a2af5
parent0153cede3726849504b04dabdebc8460c1c0fc91 (diff)
downloadpython-apt-c8f2e068538dd54206669394507a52115ce9a621.tar.gz
apt/progress/text.py: 'Sync' AcquireProgress with the one used for apt-get.
-rw-r--r--apt/progress/text.py111
1 files changed, 93 insertions, 18 deletions
diff --git a/apt/progress/text.py b/apt/progress/text.py
index 6024f124..eb196b55 100644
--- a/apt/progress/text.py
+++ b/apt/progress/text.py
@@ -36,12 +36,12 @@ class TextProgress(object):
# Fill remaining stuff with whitespace
if self._width > len(msg):
self._file.write((self._width - len(msg)) * ' ')
- else:
- self._width = max(self._width, len(msg))
+ #else:
+ # self._width = max(self._width, len(msg))
if newline:
self._file.write("\n")
else:
- self._file.write("\r")
+ #self._file.write("\r")
self._file.flush()
@@ -63,7 +63,7 @@ class OpProgress(apt_pkg.OpProgress, TextProgress):
apt_pkg.OpProgress.update(self)
if self.major_change and self.old_op:
self._write(self.old_op)
- self._write("%s... %i%%" % (self.op, self.percent), False)
+ self._write("%s... %i%%\r" % (self.op, self.percent), False)
self.old_op = self.op
def done(self):
@@ -77,21 +77,47 @@ class OpProgress(apt_pkg.OpProgress, TextProgress):
class AcquireProgress(apt_pkg.AcquireProgress, TextProgress):
"""AcquireProgress for the text interface."""
+ def __init__(self, outfile=None):
+ TextProgress.__init__(self, outfile)
+ apt_pkg.AcquireProgress.__init__(self)
+ import signal
+ self._signal = signal.signal(signal.SIGWINCH, self._winch)
+ self._winch()
+ self._id = 1L
+
+ def _winch(self, *a):
+ import fcntl
+ import termios
+ import struct
+ buf = fcntl.ioctl(self._file.fileno(),termios.TIOCGWINSZ, 8 * ' ')
+ row, col, rpx, cpx = struct.unpack('hhhh', buf)
+ self._width = col - 1 # 1 for the cursor
+
def ims_hit(self, item):
"""Called when an item is update (e.g. not modified on the server)."""
- self._write("Hit %s" % item.description)
-
- def done(self, item):
- """Called when an item is completely fetched."""
- self._write("Done %s" % item.description)
+ line = 'Hit %s' % item.description
+ if (item.owner.filesize != 0):
+ line+= ' [%sB]' % apt_pkg.size_to_str(item.owner.filesize)
+ self._write(line)
def fail(self, item):
"""Called when an item is failed."""
self._write("Fail %s" % item.description)
+ if item.owner.status == item.owner.stat_done:
+ self._write("Ign %s" % item.description)
+ else:
+ self._write("Err %s" % item.description)
+ self._write(" %s" % item.owner.error_text)
def fetch(self, item):
"""Called when some of the item's data is fetched."""
- self._write("Fetch %s" % item.description)
+ item.owner.id = self._id
+ self._id += 1
+ line = "Get:%s %s" % (item.owner.id, item.description)
+ if item.owner.filesize != 0:
+ line += (" [%sB]" % apt_pkg.size_to_str(item.owner.filesize))
+
+ self._write(line)
def pulse(self, owner):
"""Periodically invoked while the Acquire process is underway.
@@ -100,14 +126,59 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress):
percent = (((self.current_bytes + self.current_items) * 100.0) /
float(self.total_bytes + self.total_items))
- if self.current_cps > 0:
- eta = ((self.total_bytes - self.current_bytes) /
- float(self.current_cps))
- self._write("[%2.f%%] %sB/s %s" % (percent,
- apt_pkg.size_to_str(int(self.current_cps)),
- apt_pkg.time_to_str(int(eta))), False)
+
+ shown = False
+ mode = 'long'
+ tval = '%i%%' % percent
+
+ end = ""
+ if self.current_cps:
+ eta = int(float(self.total_bytes - self.current_bytes) / self.current_cps)
+ end = " %sB/s %s" % (apt_pkg.size_to_str(self.current_cps),
+ apt_pkg.time_to_str(eta))
+
+ for worker in owner.workers:
+ val = ''
+ if not worker.current_item:
+ if worker.status:
+ val += ' [%s]' % worker.status
+ shown = True
+ continue
+ shown = True
+
+ if worker.current_item.owner.id != 0:
+ val += " [%i %s" % (worker.current_item.owner.id, worker.current_item.shortdesc)
+ else:
+ val += ' [%s' % worker.current_item.description
+ if worker.current_item.owner.mode:
+ val += ' %s' % worker.current_item.owner.mode
+ if mode == 'long' and False:
+ val += ' %i' % worker.current_size
+ elif mode == 'medium' or worker.total_size == 0 or True:
+ val += ' %sB' % apt_pkg.size_to_str(worker.current_size)
+
+ # Add the total size and percent
+ if worker.total_size > 0 and worker.current_item.owner.complete == False:
+ if mode == 'short':
+ val += ' %i%%' % worker.current_size*100.0/worker.total_size
+ else:
+ val += "/%sB %i%%" % ( apt_pkg.size_to_str(worker.total_size),
+ worker.current_size*100.0/worker.total_size )
+
+ val += ']'
+
+ tval += val
+
+ if not shown:
+ tval += ' [Working]'
+
+ if self.current_cps:
+ tval += (self._width - len(end) - len(tval)) * ' ' + end
+
+ if len(tval) <= self._width:
+ self._write(tval, False)
else:
- self._write("%2.f%% [Working]" % (percent), False)
+ self._write(tval)
return True
def media_change(self, medium, drive):
@@ -119,4 +190,8 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress):
def stop(self):
"""Invoked when the Acquire process stops running."""
- self._write("Done downloading")
+ if self.fetched_bytes != 0:
+ self._write("Fetched %sB in %s (%sB/s)" % (
+ apt_pkg.size_to_str(self.fetched_bytes),
+ apt_pkg.time_to_str(self.elapsed_time),
+ apt_pkg.size_to_str(self.current_cps)))