2021-04-08 02:42:32 +03:00
#
# Copyright 2021 Red Hat, Inc.
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2021-04-08 02:42:32 +03:00
#
2015-09-19 03:28:55 +03:00
2021-06-09 01:31:44 +03:00
import sys
2015-09-19 03:28:55 +03:00
2021-06-09 01:31:44 +03:00
from . import _progresspriv
2017-10-11 14:35:40 +03:00
2018-10-25 15:37:44 +03:00
2021-04-08 02:42:32 +03:00
class Meter :
"""
2021-06-09 01:31:44 +03:00
Meter class that hides the internals of the backend implementation
from virtinst and friends
2021-04-08 02:42:32 +03:00
"""
2021-06-09 01:31:44 +03:00
# Used by virt-manager subclass
format_number = _progresspriv . format_number
format_time = _progresspriv . format_time
def __init__ ( self , quiet = False ) :
2021-04-08 02:42:32 +03:00
self . _text = None
self . _size = None
self . _total_read = 0
2021-06-09 01:31:44 +03:00
if quiet :
self . _meter = _progresspriv . BaseMeter ( )
else :
self . _meter = _progresspriv . TextMeter ( output = sys . stdout )
2017-10-11 14:35:40 +03:00
2021-04-08 02:42:32 +03:00
def start ( self , text , size ) :
self . _text = text
self . _size = size
self . _total_read = 0
2021-06-09 01:31:44 +03:00
self . _meter . start ( text , size )
2021-04-08 02:42:32 +03:00
def update ( self , new_total ) :
self . _total_read = new_total
2021-06-09 01:31:44 +03:00
self . _meter . update ( new_total )
2018-10-25 15:37:44 +03:00
2021-04-08 02:42:32 +03:00
def end ( self ) :
2021-06-09 01:31:44 +03:00
self . _meter . end ( )
2019-06-08 00:32:51 +03:00
def make_meter ( quiet ) :
2021-04-08 02:42:32 +03:00
return Meter ( quiet = quiet )
2019-06-08 00:32:51 +03:00
def ensure_meter ( meter ) :
if meter :
return meter
return make_meter ( quiet = True )