init_file_progress(fpaths,
timeint=1.0,
stream=sys.stdout,
addfmt=None)
|
|
Create a function to output progress bar while processing files.
When a collection of files is about to be processed, this function can
be used to construct a progress update function, which shows and updates
the progress bar in the terminal. The progress update function can be
called as frequently as desired during processing of a particular file,
with file path as argument. For example:
update_progress == init_file_progress(file_paths)
for file_path in file_paths:
for line in open(file_path).readlines():
update_progress(file_path)
# ...
# Processing.
# ...
update_progress() # clears last progress line
Parameter timeint determines the frequency of update, in
seconds. It should be chosen such that the progress updates themselves
(formatting, writing out to shell) are only a small fraction of total
processing time.
The output stream for the progress bar can be specified by the
stream parameter.
Additional formatting for the progress bar may be supplied by the
addfmt parameter. It can be one of: a function taking one
string parameter (the basic progress bar) and returning a string, a
delayed translation (TextTrans) with single named formatting directive
%(file)s , or a plain string with same formatting
directive.
- Parameters:
fpaths (list of strings) - collection of file paths
timeint (float) - update interval in seconds
stream (file) - the stream to output progress to
addfmt ((text) -> text or TextTrans or string) - additional format for the progress line
- Returns: (file_path, last_time, time_interval) -> new_last_time
- progress updating function
|