diff --git a/AUTHORS b/AUTHORS index 8a1b741..51db511 100644 --- a/AUTHORS +++ b/AUTHORS @@ -24,3 +24,4 @@ Patches and Suggestions - Don Spaulding - Justin Barber - Dmitry Medvinsky +- Eric Anderson diff --git a/clint/__init__.py b/clint/__init__.py index 7e52439..dbda44b 100644 --- a/clint/__init__.py +++ b/clint/__init__.py @@ -18,7 +18,7 @@ except ImportError: import collections collections.OrderedDict = OrderedDict -from arguments import * +from .arguments import * from . import textui from . import utils from .pipes import piped_in diff --git a/clint/textui/progress.py b/clint/textui/progress.py index 1a110c9..92aaf1b 100644 --- a/clint/textui/progress.py +++ b/clint/textui/progress.py @@ -33,7 +33,7 @@ ETA_INTERVAL = 1 #How many intervals (excluding the current one) to calculate the simple moving average ETA_SMA_WINDOW = 9 -def bar(it, label='', width=32, hide=HIDE_DEFAULT, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR, expected_size=None): +def bar(it, label='', width=32, hide=HIDE_DEFAULT, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR, expected_size=None, every=1): """Progress iterator. Wrap your iterables with it.""" def _show(_i): @@ -44,9 +44,11 @@ def bar(it, label='', width=32, hide=HIDE_DEFAULT, empty_char=BAR_EMPTY_CHAR, fi bar.etadisp = time.strftime('%H:%M:%S', time.gmtime(bar.eta)) x = int(width*_i/count) if not hide: - STREAM.write(BAR_TEMPLATE % ( - label, filled_char*x, empty_char*(width-x), _i, count, bar.etadisp)) - STREAM.flush() + if ((_i % every)==0 or # True every "every" updates + (_i == count)): # And when we're done + STREAM.write(BAR_TEMPLATE % ( + label, filled_char*x, empty_char*(width-x), _i, count, bar.etadisp)) + STREAM.flush() count = len(it) if expected_size is None else expected_size @@ -65,11 +67,11 @@ def bar(it, label='', width=32, hide=HIDE_DEFAULT, empty_char=BAR_EMPTY_CHAR, fi _show(i+1) if not hide: - STREAM.write('\n') - STREAM.flush() + STREAM.write('\n') + STREAM.flush() -def dots(it, label='', hide=HIDE_DEFAULT): +def dots(it, label='', hide=HIDE_DEFAULT, every=1): """Progress iterator. Prints a dot for each item being iterated""" count = 0 @@ -77,10 +79,11 @@ def dots(it, label='', hide=HIDE_DEFAULT): if not hide: STREAM.write(label) - for item in it: + for (i, item) in enumerate(it): if not hide: - STREAM.write(DOTS_CHAR) - sys.stderr.flush() + if (i % every)==0: # True every "every" updates + STREAM.write(DOTS_CHAR) + sys.stderr.flush() count += 1 @@ -90,7 +93,7 @@ def dots(it, label='', hide=HIDE_DEFAULT): STREAM.flush() -def mill(it, label='', hide=HIDE_DEFAULT, expected_size=None): +def mill(it, label='', hide=HIDE_DEFAULT, expected_size=None, every=1): """Progress iterator. Prints a mill while iterating over the items.""" def _mill_char(_i): @@ -101,9 +104,12 @@ def mill(it, label='', hide=HIDE_DEFAULT, expected_size=None): def _show(_i): if not hide: - STREAM.write(MILL_TEMPLATE % ( - label, _mill_char(_i), _i, count)) - STREAM.flush() + if ((_i % every)==0 or # True every "every" updates + (_i == count)): # And when we're done + + STREAM.write(MILL_TEMPLATE % ( + label, _mill_char(_i), _i, count)) + STREAM.flush() count = len(it) if expected_size is None else expected_size