wget_util
bar_custom
¶
Return progress bar string for given values in one of three styles depending on available width.
This function was modified from wget source code at https://bitbucket.org/techtonik/python-wget/src/default/.
If total width is unknown or <= 0, the bar will show a bytes counter using two adaptive styles: %s / unknown %s
If there is not enough space on the screen, do not display anything. The returned string doesn't include control characters like used to place cursor at the beginning of the line to erase previous content.
This function leaves one free character at the end of the string to avoid automatic linefeed on Windows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current |
float
|
The current amount of progress. |
required |
total |
float
|
The total amount of progress required by the task. |
required |
width |
int
|
The available width. |
80
|
Returns:
Type | Description |
---|---|
str
|
A formatted string to display the current progress. |
Source code in fastestimator/fastestimator/util/wget_util.py
callback_progress
¶
Callback function for urlretrieve that is called when a connection is created and then once for each block.
Draws adaptive progress bar in terminal/console.
Use sys.stdout.write() instead of "print", because it allows one more symbols at the line end without triggering a linefeed on Windows.
import wget
wget.callback_progress = fe.util.callback_progress
wget.download('http://url.com', '/save/dir', bar=fe.util.bar_custom)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blocks |
int
|
number of blocks transferred so far. |
required |
block_size |
int
|
in bytes. |
required |
total_size |
int
|
in bytes, can be -1 if server doesn't return it. |
required |
bar_function |
Callable[[int, int, int], str]
|
another callback function to visualize progress. |
required |