fastwater.otm_gpl.progressbar module

@note … this work is based on a collaborative effort of the Telemac-Mascaret consortium

@details This library provides a text mode progressbar. This is tipically used to display the progress of a long running operation, providing a visual clue that processing is underway.

The ProgressBar class manages the progress, and the format of the line is given by a number of widgets. A widget is an object that may display diferently depending on the state of the progress. There are three types of widget:

  • a string, which always shows itself (such as “Time(s): “) ;

  • a ProgressBarWidget, which may return a diferent value every time

    it’s update method is called (such as ” 3%”); and

  • a ProgressBarWidgetHFill, which is like ProgressBarWidget,

    except it expands to fill the remaining width of the line (such as “[##### ]”).

The progressbar module is very easy to use, yet very powerful. And automatically supports features like auto-resizing when available.

Since the progress bar is incredibly customizable you can specify different widgets of any type in any order. You can even write your own widgets! However, since there are already a good number of widgets you should probably play around with them before moving on to create your own widgets.

class fastwater.otm_gpl.progressbar.Bar(marker='#', left='|', right='|')[source]

Bases: ProgressBarWidgetHFill

The bar of progress. It will strech to fill the line.

marker - string or updatable object to use as a marker left - string or updatable object to use as a left border right - string or updatable object to use as a right border fill - character to use for the empty part of the progress bar fill_left - whether to fill from the left or the right

Initialization function for Bar class @param marker (string or updatable object) to use as a marker @param left (string or updatable object) to use as a left border @param right (string or updatable object) use as a right border

update(pbar, width)[source]

Update progress bar @param pbar (object) ProgressBar object @param width (float) width of the progress bar @return (string) new percentage progress bar

class fastwater.otm_gpl.progressbar.ETA[source]

Bases: ProgressBarWidget

Widget for the Estimated Time of Arrival

format_time(seconds)[source]

Float time to string format @param seconds (float) Time in s @return (string)

update(pbar)[source]

Update progress bar

@param pbar (object) ProgressBar object

@return (string) new sprogress bar

class fastwater.otm_gpl.progressbar.FileTransferSpeed[source]

Bases: ProgressBarWidget

Widget for showing the transfer speed (useful for file transfers).

Initialization of FileTransferSpeed class

update(pbar)[source]

Update progress bar element @param pbar (object) ProgressBar object @return (string) new element progress bar

class fastwater.otm_gpl.progressbar.Percentage[source]

Bases: ProgressBarWidget

Just the percentage done.

update(pbar)[source]

” Update progress bar percentage @param pbar (object) ProgressBar object @return (string) new percentage progress bar

class fastwater.otm_gpl.progressbar.ProgressBar(maxval=100, widgets=[<fastwater.otm_gpl.progressbar.Bar object>, ' ', <fastwater.otm_gpl.progressbar.Percentage object>, ' ', <fastwater.otm_gpl.progressbar.ETA object>], term_width=None, f_d=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>)[source]

Bases: object

The ProgressBar class which updates and prints the bar.

A common way of using it is like:

pbar = ProgressBar().start() for i in range(100):

… # do something … pbar.update(i+1)

pbar.finish()

You can also use a ProgressBar as an iterator:

progress = ProgressBar() for i in progress(some_iterable):

… # do something

The term_width parameter represents the current terminal width. If the parameter is set to an integer then the progress bar will use that, otherwise it will attempt to determine the terminal width falling

back to 80 columns if the width cannot be determined.

When implementing a widget’s update method you are passed a reference to the current progress bar. As a result, you have access to the ProgressBar’s methods and attributes. Although there is nothing preventing you from changing the ProgressBar you should treat it as read only.

Useful methods and attributes include:
  • currval: current progress (0 <= currval <= maxval)

  • maxval: maximum (and final) value

  • finished: True if the bar has finished (reached 100%)

  • start_time: the time when start() method of ProgressBar

  • seconds_elapsed: seconds elapsed since start_time and last call

    to update

  • percentage(): progress in percent [0..100]

finish()[source]
handle_resize(signum, frame)[source]
percentage()[source]

@return Returns the percentage of the progress.

start()[source]
trace()[source]

Leave a trace on screen of the progress bar and carry on to the next line.

update(value, carriage='\r')[source]

Updates the progress bar to a new value.

write(string, value)[source]

Move the progress bar along.

class fastwater.otm_gpl.progressbar.ProgressBarWidget[source]

Bases: object

This is a variable width element of ProgressBar formatting. The ProgressBar object will call it’s update value, informing the

width this object must the made. This is like TeX hfill, it will expand to fill the line. You can use more than one in the same line, and they will all have the same width, and together will fill the line.

update(pbar)[source]
Returns the string representing the widget.

The parameter pbar is a reference to the calling ProgressBar,

where one can access attributes of the class for knowing how the update must be made.

At least this function must be overriden.

@param pbar (object) pbar ProgressBar object

@return nothing

class fastwater.otm_gpl.progressbar.ProgressBarWidgetHFill[source]

Bases: object

This is a variable width element of ProgressBar formatting.

The ProgressBar object will call it’s update value, informing the

width this object must the made. This is like TeX hfill, it will expand to fill the line. You can use more than one in the same line, and they will all have the same width, and together will fill the line.

update(pbar, width)[source]

Returns the string representing the widget. The parameter pbar is a reference to the calling ProgressBar, where one can access attributes of the class for knowing how the update must be made. The parameter width is the total horizontal width the widget must have.

At least this function must be overriden.

@param pbar (object) pbar ProgressBar object

@param width (float) total horizontal width the widget must have

class fastwater.otm_gpl.progressbar.ReverseBar(marker='#', left='|', right='|')[source]

Bases: Bar

The reverse bar of progress, or bar of regress. :)

Initialization function for Bar class @param marker (string or updatable object) to use as a marker @param left (string or updatable object) to use as a left border @param right (string or updatable object) use as a right border

update(pbar, width)[source]

Update progress bar @param pbar (object) ProgressBar object @param width (float) width of the progress bar @return (string) new percentage progress bar

class fastwater.otm_gpl.progressbar.RotatingMarker(markers='|/-\\')[source]

Bases: ProgressBarWidget

A rotating marker for filling the bar of progress.

Initialization function for RotatingMarker class @param markers (string or updatable object) to use as a marker

update(pbar)[source]

Update progress bar element @param pbar (object) ProgressBar object @return (string) new element progress bar

class fastwater.otm_gpl.progressbar.SubProgressBar(maxval=100)[source]

Bases: ProgressBar

class fastwater.otm_gpl.progressbar.UnknownLength[source]

Bases: object

This is an element of ProgressBar formatting. The ProgressBar object will call it’s update value when an update

is needed. It’s size may change between call, but the results will not be good if the size changes drastically and repeatedly.

fastwater.otm_gpl.progressbar.main()[source]

Main function of progressbar