r301 - branches/rewrite/src
Enrico Zini
partial-mirror-devel@lists.alioth.debian.org
Thu, 11 Nov 2004 08:43:28 -0700
Author: enrico
Date: Thu Nov 11 08:43:24 2004
New Revision: 301
Modified:
branches/rewrite/src/DisplayStatus.py
Log:
Added unified update() method to be used by other kind of status displays
Added functions to query the terminal with and use them instead of the hardcoded '80'
Modified: branches/rewrite/src/DisplayStatus.py
==============================================================================
--- branches/rewrite/src/DisplayStatus.py (original)
+++ branches/rewrite/src/DisplayStatus.py Thu Nov 11 08:43:24 2004
@@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $Id$
-import sys
+import sys, fcntl, struct, termios
from os.path import basename
class StatusItem:
@@ -61,27 +61,39 @@
def start(self, url, size):
self._items[url] = StatusItem()
self._items[url]['size'] = size
+ self.update()
def update(self, url, current):
self._items[url]['current'] = current
+ self.update()
def errored(self, url, message):
if not self._items.has_key(url):
self._items[url] = StatusItem()
self._items[url]['errored'] = message
+ self.update()
+
+ def update(self):
+ pass
+
class TextDisplayStatus(BaseDisplayStatus):
+ def screenwidth(self):
+ return struct.unpack("hhhh", fcntl.ioctl(1, termios.TIOCGWINSZ, " "))[1]
+
def start(self, url, size):
BaseDisplayStatus.start(self, url, size)
- sys.stdout.write("\r" + " " * 80 + "\rGetting %d: %s\n" % (self._items[url]['id'], url))
+ sw = self.screenwidth()
+ sys.stdout.write("\r" + " " * sw + "\rGetting %d: %s\n" % (self._items[url]['id'], url))
sys.stdout.flush()
def update(self, url, current):
BaseDisplayStatus.update(self, url, current)
+ sw = self.screenwidth()
if current == self._items[url]['size']:
- sys.stdout.write("\r" + " " * 80 + "\rDone: %s\n" % url)
+ sys.stdout.write("\r" + " " * sw + "\rDone: %s\n" % url)
self._items[url]['finished'] = True
- sys.stdout.write("\r" + " " * 80 + "\r")
+ sys.stdout.write("\r" + " " * sw + "\r")
for url in self._items.keys():
if self._items[url]['finished'] or self._items[url]['errored']:
continue
@@ -97,5 +109,6 @@
def errored(self, url, message):
BaseDisplayStatus.errored(self, url, message)
- sys.stdout.write("\r" + " " * 80 + "\rFailed: %s %s\n" % (url, message))
+ sw = self.screenwidth()
+ sys.stdout.write("\r" + " " * sw + "\rFailed: %s %s\n" % (url, message))
sys.stdout.flush()