diff options
author | Daniil Baturin <daniil@vyos.io> | 2023-10-14 12:53:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 12:53:50 +0100 |
commit | bdc5a7c12464ca46858fdf3d753dcc989a6975af (patch) | |
tree | 39b4df2db1507b11d77a51bacaf9db18faf2cf00 /python/vyos/utils/io.py | |
parent | 3b202fa469f58b35d1ce2e1cb91015f9551618c8 (diff) | |
parent | 8ab27f839a5545464db46ea14a2d5326b86553a6 (diff) | |
download | vyos-1x-bdc5a7c12464ca46858fdf3d753dcc989a6975af.tar.gz vyos-1x-bdc5a7c12464ca46858fdf3d753dcc989a6975af.zip |
Merge pull request #2365 from vyos/mergify/bp/sagitta/pr-2359
remote: T5650: Resize-aware progressbar implementation (backport #2359)
Diffstat (limited to 'python/vyos/utils/io.py')
-rw-r--r-- | python/vyos/utils/io.py | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py index 843494855..5fffa62f8 100644 --- a/python/vyos/utils/io.py +++ b/python/vyos/utils/io.py @@ -24,45 +24,6 @@ def print_error(str='', end='\n'): sys.stderr.write(end) sys.stderr.flush() -def make_progressbar(): - """ - Make a procedure that takes two arguments `done` and `total` and prints a - progressbar based on the ratio thereof, whose length is determined by the - width of the terminal. - """ - import shutil, math - col, _ = shutil.get_terminal_size() - col = max(col - 15, 20) - def print_progressbar(done, total): - if done <= total: - increment = total / col - length = math.ceil(done / increment) - percentage = str(math.ceil(100 * done / total)).rjust(3) - print_error(f'[{length * "#"}{(col - length) * "_"}] {percentage}%', '\r') - # Print a newline so that the subsequent prints don't overwrite the full bar. - if done == total: - print_error() - return print_progressbar - -def make_incremental_progressbar(increment: float): - """ - Make a generator that displays a progressbar that grows monotonically with - every iteration. - First call displays it at 0% and every subsequent iteration displays it - at `increment` increments where 0.0 < `increment` < 1.0. - Intended for FTP and HTTP transfers with stateless callbacks. - """ - print_progressbar = make_progressbar() - total = 0.0 - while total < 1.0: - print_progressbar(total, 1.0) - yield - total += increment - print_progressbar(1, 1) - # Ignore further calls. - while True: - yield - def ask_input(question, default='', numeric_only=False, valid_responses=[]): question_out = question if default: |