mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 10:18:12 +00:00
ProgressIndicatorPercent: remove same_line
This commit is contained in:
parent
e7d44cec39
commit
ab31ffaa85
2 changed files with 10 additions and 28 deletions
|
@ -1107,14 +1107,13 @@ def yes(msg=None, false_msg=None, true_msg=None, default_msg=None,
|
|||
class ProgressIndicatorPercent:
|
||||
LOGGER = 'borg.output.progress'
|
||||
|
||||
def __init__(self, total, step=5, start=0, same_line=True, msg="%3.0f%%"):
|
||||
def __init__(self, total, step=5, start=0, msg="%3.0f%%"):
|
||||
"""
|
||||
Percentage-based progress indicator
|
||||
|
||||
:param total: total amount of items
|
||||
:param step: step size in percent
|
||||
:param start: at which percent value to start
|
||||
:param same_line: if True, emit output always on same line
|
||||
:param msg: output message, must contain one %f placeholder for the percentage
|
||||
"""
|
||||
self.counter = 0 # 0 .. (total-1)
|
||||
|
@ -1122,7 +1121,6 @@ def __init__(self, total, step=5, start=0, same_line=True, msg="%3.0f%%"):
|
|||
self.trigger_at = start # output next percentage value when reaching (at least) this
|
||||
self.step = step
|
||||
self.msg = msg
|
||||
self.same_line = same_line
|
||||
self.handler = None
|
||||
self.logger = logging.getLogger(self.LOGGER)
|
||||
|
||||
|
@ -1132,7 +1130,7 @@ def __init__(self, total, step=5, start=0, same_line=True, msg="%3.0f%%"):
|
|||
if not self.logger.handlers:
|
||||
self.handler = logging.StreamHandler(stream=sys.stderr)
|
||||
self.handler.setLevel(logging.INFO)
|
||||
self.handler.terminator = '\r' if self.same_line else '\n'
|
||||
self.handler.terminator = '\r'
|
||||
|
||||
self.logger.addHandler(self.handler)
|
||||
if self.logger.level == logging.NOTSET:
|
||||
|
@ -1162,7 +1160,6 @@ def output(self, percent):
|
|||
self.logger.info(self.msg % percent)
|
||||
|
||||
def finish(self):
|
||||
if self.same_line:
|
||||
self.logger.info(" " * len(self.msg % 100.0))
|
||||
|
||||
|
||||
|
|
|
@ -870,24 +870,9 @@ def test_yes_env_output(capfd, monkeypatch):
|
|||
assert 'yes' in err
|
||||
|
||||
|
||||
def test_progress_percentage_multiline(capfd):
|
||||
pi = ProgressIndicatorPercent(1000, step=5, start=0, same_line=False, msg="%3.0f%%")
|
||||
pi.show(0)
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ' 0%\n'
|
||||
pi.show(420)
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ' 42%\n'
|
||||
pi.show(1000)
|
||||
out, err = capfd.readouterr()
|
||||
assert err == '100%\n'
|
||||
pi.finish()
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ''
|
||||
|
||||
|
||||
def test_progress_percentage_sameline(capfd):
|
||||
pi = ProgressIndicatorPercent(1000, step=5, start=0, msg="%3.0f%%")
|
||||
pi.logger.setLevel('INFO')
|
||||
pi.show(0)
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ' 0%\r'
|
||||
|
@ -904,22 +889,22 @@ def test_progress_percentage_sameline(capfd):
|
|||
|
||||
|
||||
def test_progress_percentage_step(capfd):
|
||||
pi = ProgressIndicatorPercent(100, step=2, start=0, same_line=False, msg="%3.0f%%")
|
||||
pi = ProgressIndicatorPercent(100, step=2, start=0, msg="%3.0f%%")
|
||||
pi.logger.setLevel('INFO')
|
||||
pi.show()
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ' 0%\n'
|
||||
assert err == ' 0%\r'
|
||||
pi.show()
|
||||
out, err = capfd.readouterr()
|
||||
assert err == '' # no output at 1% as we have step == 2
|
||||
pi.show()
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ' 2%\n'
|
||||
assert err == ' 2%\r'
|
||||
|
||||
|
||||
def test_progress_percentage_quiet(capfd):
|
||||
logging.getLogger('borg.output.progress').setLevel(logging.WARN)
|
||||
|
||||
pi = ProgressIndicatorPercent(1000, step=5, start=0, same_line=False, msg="%3.0f%%")
|
||||
pi = ProgressIndicatorPercent(1000, step=5, start=0, msg="%3.0f%%")
|
||||
pi.logger.setLevel('WARN')
|
||||
pi.show(0)
|
||||
out, err = capfd.readouterr()
|
||||
assert err == ''
|
||||
|
|
Loading…
Reference in a new issue