Beispiel #1
0
def progress(count):
    """Demonstrates the progress bar."""
    items = range_type(count)

    def process_slowly(item):
        time.sleep(0.002 * random.random())

    def filter(items):
        for item in items:
            if random.random() > 0.3:
                yield item

    with click.progressbar(items,
                           label='Processing accounts',
                           fill_char=click.style('#', fg='green')) as bar:
        for item in bar:
            process_slowly(item)

    def show_item(item):
        if item is not None:
            return 'Item #%d' % item

    with click.progressbar(filter(items),
                           label='Committing transaction',
                           fill_char=click.style('#', fg='yellow'),
                           item_show_func=show_item) as bar:
        for item in bar:
            process_slowly(item)

    with click.progressbar(length=count,
                           label='Counting',
                           bar_template='%(label)s  %(bar)s | %(info)s',
                           fill_char=click.style(u'█', fg='cyan'),
                           empty_char=' ') as bar:
        for item in bar:
            process_slowly(item)

    with click.progressbar(length=count,
                           width=0,
                           show_percent=False,
                           show_eta=False,
                           fill_char=click.style('#', fg='magenta')) as bar:
        for item in bar:
            process_slowly(item)

    # 'Non-linear progress bar'
    steps = [math.exp(x * 1. / 20) - 1 for x in range(20)]
    count = int(sum(steps))
    with click.progressbar(length=count,
                           show_percent=False,
                           label='Slowing progress bar',
                           fill_char=click.style(u'█', fg='green')) as bar:
        for item in steps:
            time.sleep(item)
            bar.update(item)
Beispiel #2
0
 def cli():
     with click.progressbar(tuple(range(10)), label=label) as progress:
         for thing in progress:
             pass
Beispiel #3
0
 def cli():
     with click.progressbar(Hinted(10), label='test') as progress:
         for thing in progress:
             pass
Beispiel #4
0
 def cli():
     with click.progressbar(tuple(range(10)), label=label) as progress:
         for thing in progress:
             fake_clock.advance_time()
Beispiel #5
0
 def cli():
     with click.progressbar(Hinted(10), label='test') as progress:
         for thing in progress:
             fake_clock.advance_time()
Beispiel #6
0
 def cli():
     with click.progressbar(range(4)) as progress:
         for _ in progress:
             fake_clock.advance_time()
             print("")
Beispiel #7
0
def test_progressbar_yields_all_items(runner):
    with click.progressbar(range(3)) as progress:
        assert len(list(progress)) == 3