(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR)
Progress iterator. Wrap your iterables with it.
Progress iterator. Wrap your iterables with it.
Progress iterator . Wrap your iterables with it .
def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR):
    """Progress iterator. Wrap your iterables with it."""

    def _show(_i):
        if (time.time() - bar.etadelta) > ETA_INTERVAL:
            bar.etadelta = time.time()
            bar.ittimes = bar.ittimes[-ETA_SMA_WINDOW:]+[-(bar.start-time.time())/(_i+1)]
            bar.eta = sum(bar.ittimes)/float(len(bar.ittimes)) * (count-_i)
            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()

    count = len(it)

    bar.start    = time.time()
    bar.ittimes  = []
    bar.eta      = 0
    bar.etadelta = time.time()
    bar.etadisp  = time.strftime('%H:%M:%S', time.gmtime(bar.eta))

    if count:
        _show(0)

    for i, item in enumerate(it):

        yield item
        _show(i+1)

    if not hide:
        STREAM.write('\n')
        STREAM.flush()
def bar ( it , label = '' , width = 32 , hide = False , empty_char = BAR_EMPTY_CHAR , filled_char = BAR_FILLED_CHAR ) : def _show ( _i ) : if ( time . time ( ) - bar . etadelta ) > ETA_INTERVAL : bar . etadelta = time . time ( ) bar . ittimes = bar . ittimes [ - ETA_SMA_WINDOW : ] + [ - ( bar . start - time . time ( ) ) / ( _i + 1 ) ] bar . eta = sum ( bar . ittimes ) / float ( len ( bar . ittimes ) ) * ( count - _i ) 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 ( ) count = len ( it ) bar . start = time . time ( ) bar . ittimes = [ ] bar . eta = 0 bar . etadelta = time . time ( ) bar . etadisp = time . strftime ( '%H:%M:%S' , time . gmtime ( bar . eta ) ) if count : _show ( 0 ) for i , item in enumerate ( it ) : yield item _show ( i + 1 ) if not hide : STREAM . write ( '\n' ) STREAM . flush ( )