diff options
author | pierre-yves david <pierre-yves.david@insa-lyon.fr> | 2008-06-29 13:13:36 +0200 |
---|---|---|
committer | pierre-yves david <pierre-yves.david@insa-lyon.fr> | 2008-06-29 13:13:36 +0200 |
commit | 3b59b4e32e2b01057152e81f5843df583be613a6 (patch) | |
tree | a2d721de09260f7dabc969f1c377027bda644374 /shellutils.py | |
parent | 1fafea83345699ead8c03a8b2b4a9f50de1574d1 (diff) | |
download | logilab-common-3b59b4e32e2b01057152e81f5843df583be613a6.tar.gz |
prevent overflow in ProgressBar
Diffstat (limited to 'shellutils.py')
-rw-r--r-- | shellutils.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/shellutils.py b/shellutils.py index 6f8d929..cad5b33 100644 --- a/shellutils.py +++ b/shellutils.py @@ -191,8 +191,8 @@ def release_lock(lock_file): class ProgressBar(object): """a simple text progression bar""" - def __init__(self, nbops, size=20., stream=sys.stdout): - self._fstr = '\r[%%-%ss]' % size + def __init__(self, nbops, size=20, stream=sys.stdout): + self._fstr = '\r[%%-%ss]' % int(size) self._stream = stream self._total = nbops self._size = size @@ -205,5 +205,9 @@ class ProgressBar(object): progress = int((float(self._current)/float(self._total))*self._size) if progress > self._progress: self._progress = progress - self._stream.write(self._fstr % ('.' * progress) ) - self._stream.flush() + self.refresh() + + def refresh(self): + """refresh the progression bar display""" + self._stream.write(self._fstr % ('.' * min(self._progress, self._size)) ) + self._stream.flush() |