Giter Club home page Giter Club logo

progressbar's Introduction

Python Progressbar

A progressbar utility for command line programs. Progressbar is a Python module which contains two class so far:

  1. ProgressBar
  2. AnimatedProgressBar

ProgressBar class implements all the base stuff that makes progress bars work as they do and allows some basic customization. AnimatedProgressBar class extends ProgressBar to allow you to use it straightforward in your scripts. By default the AnimatedProgressBar sends the output to sys.stdout but you can change this passing the stdout keyword parameter which must be a file-like object.

Usage

Here is some basic usage with the default options:

>>> from progressbar import ProgressBar
>>> p = ProgressBar()
>>> print p
[>............] 0%
>>> p + 1
>>> print p
[=>...........] 10%
>>> p + 9
>>> print p
[============>] 0%

And here another example with different options:

>>> from progressbar import ProgressBar
>>> custom_options = {
...     'end': 100,
...     'width': 20,
...     'fill': '#',
...     'format': '%(progress)s%% [%(fill)s%(blank)s]'
... }
>>> p = ProgressBar(**custom_options)
>>> print p
0% [....................]
>>> p + 5
>>> print p
5% [#...................]
>>> p + 95
>>> print p
100% [####################]

Finally, a real example where I had to use it:

>>> import ftplib
>>> import progressbar
>>>
>>> ftp = ftplib.FTP('ftp.myserver.com', 'user', 'passwd')
>>> filesize = ftp.size('path/to/remotefile.zip')
>>> progress = progressbar.AnimatedProgressBar(end=filesize, width=50)
>>>
>>> with open('localfile.zip', 'w') as f:
>>>     def callback(chunk):
>>>         f.write(chunk)
>>>         progress + len(chunk)
>>>
>>>         # Visual feedback of the progress!
>>>         progress.show_progress()
>>>
>>>     ftp.retrbinary('RETR path/to/remotefile.zip', callback)

Contribution

If you find it useful, fork the repository, improve it and request a pull.

progressbar's People

Contributors

hgrzywacz avatar offlinemark avatar ralfharing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

progressbar's Issues

Adding a license

Hi, could you please indicate your program license terms?
I would like to use it.

Progress blinks (at least in Jython)

Thanks to Michal Niklas who said:

I noticed that AnimatedProgressBar blinks, so I changed show_progress() method to check if progress indicator changed:

def init(self, _args, *_kwargs):
super(AnimatedProgressBar, self).init(_args, *_kwargs)
self.stdout = kwargs.get('stdout', sys.stdout)
self.last_indicator = ''

def show_progress(self):
indicator = str(self)
if indicator == self.last_indicator:
return
if hasattr(self.stdout, 'isatty') and self.stdout.isatty():
self.stdout.write('\r')
else:
self.stdout.write('\n')
self.stdout.write(indicator)
self.stdout.flush()
self.last_indicator = indicator

Improve library design

This was one of the first things I did when learning Python and you can tell there are things that aren't pythonic at all such as updating the progressbar progress:

progressbar_instance + progress

Also, the ProgressBar class encapsulates display logic:

custom_options = {
    'end': 100,
    'width': 20,
    'fill': '#',
    'format': '%(progress)s%% [%(fill)s%(blank)s]'
}
p = ProgressBar(**custom_options)

thing that in my opinion should be responsability of some kind of widget class that we could pass to ProgressBar with dependency injection.

So the idea is to get to this point:

console_widget = ConsoleWidget(fill='#', width=20, ...)
console_nyan_bar_widget = ConsoleNyanWidget(...)

p = ProgressBar(end=100, widget=...)

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.