Package commons :: Module progress
[hide private]
[frames] | no frames]

Module progress

source code

Long-running processes and facilities to let them report their progress.

Functions [hide private]
 
urlopen_progress(url, output_stream=None, fields='OoRrtcl', chunk_size=4096)
Progress reporter for urlopen().
source code
 
render_progress(caption, ratio, width)
Draws a progress bar on the console.
source code
Variables [hide private]
  __package__ = 'commons'
Function Details [hide private]

urlopen_progress(url, output_stream=None, fields='OoRrtcl', chunk_size=4096)

source code 

Progress reporter for urlopen(). This is a generator which, upon receipt of each chunk of data, yields a tuple of values. This tuple reports data about the progress of the download; the exact values yielded can be configured.

Based on http://mail.python.org/pipermail/python-list/2006-January/320635.html.

Parameters:
  • url (str) - The URL to fetch.
  • output_stream (stream) - The file-like stream object to write to.
  • fields (str) - A set of characters indicating what data to report. The following characters have meaning:
    • O: offset where the first byte of the latest chunk is to be written
    • o: offset percentage
    • R: received number of bytes (offset + length of latest chunk)
    • r: received percentage
    • t: total number of bytes
    • c: the latest chunk
    • l: the length of the latest chunk
  • chunk_size (int) - The requested chunk size.

render_progress(caption, ratio, width)

source code 

Draws a progress bar on the console. First prints a carriage return, so this function can be called repeatedly to create an "animated" progress bar.

Parameters:
  • caption (str) - The label printed to the left of the bar.
  • ratio (float) - The percentage progress.
  • width (int) - The width of the progress bar, in characters.