virt-manager/virtinst/progress.py
Cole Robinson 078178f476 progress: Drop tqdm and revert back to local urlgrabber copy
I thought tqdm was available everywhere, but it does not seem like
it will be in RHEL9. Revert back to the old urlgrabber copy, now
stored in virtinst/_progresspriv.py. If we ever want to try tqdm
again, we can just revert this commit

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2021-06-09 16:52:11 -04:00

53 lines
1.1 KiB
Python

#
# Copyright 2021 Red Hat, Inc.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
#
import sys
from . import _progresspriv
class Meter:
"""
Meter class that hides the internals of the backend implementation
from virtinst and friends
"""
# Used by virt-manager subclass
format_number = _progresspriv.format_number
format_time = _progresspriv.format_time
def __init__(self, quiet=False):
self._text = None
self._size = None
self._total_read = 0
if quiet:
self._meter = _progresspriv.BaseMeter()
else:
self._meter = _progresspriv.TextMeter(output=sys.stdout)
def start(self, text, size):
self._text = text
self._size = size
self._total_read = 0
self._meter.start(text, size)
def update(self, new_total):
self._total_read = new_total
self._meter.update(new_total)
def end(self):
self._meter.end()
def make_meter(quiet):
return Meter(quiet=quiet)
def ensure_meter(meter):
if meter:
return meter
return make_meter(quiet=True)