From 270afcca03c72e0f950c0f4042f31051ebec9892 Mon Sep 17 00:00:00 2001 From: Jason Piper Date: Mon, 23 Jan 2012 13:50:45 +0000 Subject: [PATCH] Added progress bar ETA Very simplistic, currently updates every iteration (not a performance issue, but not the prettiest way to do it) --- clint/textui/progress.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/clint/textui/progress.py b/clint/textui/progress.py index d0f93c7..369b19a 100644 --- a/clint/textui/progress.py +++ b/clint/textui/progress.py @@ -11,10 +11,11 @@ This module provides the progressbar functionality. from __future__ import absolute_import import sys +import time STREAM = sys.stderr -BAR_TEMPLATE = '%s[%s%s] %i/%i\r' +BAR_TEMPLATE = '%s[%s%s] %i/%i - %s\r' MILL_TEMPLATE = '%s %s %i/%i\r' DOTS_CHAR = '.' @@ -26,14 +27,17 @@ def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_ch """Progress iterator. Wrap your iterables with it.""" def _show(_i): + ETA = -((start-time.time())/(_i+1)) * (count-_i) + ETADisp = time.strftime('%H:%M:%S', time.gmtime(ETA)) x = int(width*_i/count) if not hide: STREAM.write(BAR_TEMPLATE % ( - label, filled_char*x, empty_char*(width-x), _i, count)) + label, filled_char*x, empty_char*(width-x), _i, count, ETADisp)) STREAM.flush() count = len(it) + start = time.time() if count: _show(0)