This module provides a wrapper that outputs simple progress meters to the command line based on source file positions, or an arbitrary counter. The ProgressMeter class is the major element that this module provides.
This class provides a simple means of rendering a progress meter at the command line. It can be driven either with a file object (in which case the current position of the file is used) or with an arbitrary value (which your code must provide). In the case of a file-object, the file must be seekable (so that the class can determine the overall length of the file). If fileobj is not specified, then total must be specified.
The class is intended to be used as a context manager. Upon entry it will render an initial progress meter, and will update it at reasonable intervals (dictated by the max_wait parameter) in response to calls to the update() method. When you leave the context, the progress meter will be automatically erased if hide_on_finish is True (which it is by default).
Within the context, the hide() and show() methods can be used to temporarily hide and show the progress meter (in order to display some status text, for example).
Parameters: |
|
---|
A ProgressMeter style that renders a simple spinning line.
A ProgressMeter style that renders a simple percentage counter.
A ProgressMeter style that renders an looping series of dots.
A ProgressMeter style that renders a full progress bar and percentage.
A ProgressMeter style for those that remember FTP’s hash command!
The most basic usage of this class is as follows:
import io
from lars import iis, csv, progress
with io.open('logs\iis.txt', 'rb') as infile, \
io.open('iis.csv', 'wb') as outfile, \
progress.ProgressMeter(infile) as meter, \
iis.IISSource(infile) as source, \
csv.CSVTarget(outfile) as target:
for row in source:
target.write(row)
meter.update()
Note that you do not need to worry about the detrimental performance effects of calling update() too often; the class ensures that repeated calls are ignored until max_wait seconds have elapsed since the last update.
Alternatively, if you wish to update according to, say, the number of files to process you could use something like the following example (which also demonstrates temporarily hiding the progress meter in order to show the current filename):
import os
import io
from lars import iis, csv, progress
files = os.listdir('.')
with progress.ProgressMeter(total=len(files), style=progress.BarStyle) as meter:
for file_num, file_name in enumerate(files):
meter.hide()
print "Processing %s" % file_name
meter.show()
with io.open(file_name, 'rb') as infile, \
io.open(os.path.splitext(file_name)[0] + '.csv', 'wb') as outfile, \
iis.IISSource(infile) as source, \
csv.CSVTarget(outfile) as target:
for row in source:
target.write(row)
meter.update(file_num)