summaryrefslogtreecommitdiff
path: root/shellutils.py
diff options
context:
space:
mode:
authorPierre-Yves David <pierre-yves.david@logilab.fr>2008-06-26 17:53:32 +0200
committerPierre-Yves David <pierre-yves.david@logilab.fr>2008-06-26 17:53:32 +0200
commitfaad3def4cb6cc286df60265c67197cec359bfb4 (patch)
tree919f7997def755ce8d26284d157f8e2bd6550983 /shellutils.py
parent8cd622fe855c93c16f01a31d95418ba7ba539377 (diff)
downloadlogilab-common-faad3def4cb6cc286df60265c67197cec359bfb4.tar.gz
ProgressBar progress propertly now
Diffstat (limited to 'shellutils.py')
-rw-r--r--shellutils.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/shellutils.py b/shellutils.py
index 70f5c4b..d855ae5 100644
--- a/shellutils.py
+++ b/shellutils.py
@@ -192,16 +192,15 @@ class ProgressBar(object):
"""a simple text progression bar"""
def __init__(self, nbops, size=20., stream=sys.stdout):
- self._dotevery = max(nbops / size, 1)
self._fstr = '\r[%%-%ss]' % size
- self._dotcount, self._dots = 1, []
self._stream = stream
+ self._total = nbops
+ self._size = size
+ self._current = 0
def update(self):
"""update the progression bar"""
- self._dotcount += 1
- if self._dotcount >= self._dotevery:
- self._dotcount = 0
- self._dots.append('.')
- self._stream.write(self._fstr % ''.join(self._dots))
- self._stream.flush()
+ self._current += 1
+ progress = int((float(self._current)/float(self._total))*self._size)
+ self._stream.write(self._fstr % ('.' * progress) )
+ self._stream.flush()