From ab31ffaa85d4871f405f38e8f1e7385f19f6205f Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Sun, 21 Aug 2016 17:36:51 +0200 Subject: [PATCH] ProgressIndicatorPercent: remove same_line --- src/borg/helpers.py | 9 +++------ src/borg/testsuite/helpers.py | 29 +++++++---------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/borg/helpers.py b/src/borg/helpers.py index c9d99ef97..3d30692f2 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -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,8 +1160,7 @@ 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)) + self.logger.info(" " * len(self.msg % 100.0)) class ProgressIndicatorEndless: diff --git a/src/borg/testsuite/helpers.py b/src/borg/testsuite/helpers.py index c398ee28f..5f5a3806c 100644 --- a/src/borg/testsuite/helpers.py +++ b/src/borg/testsuite/helpers.py @@ -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 == ''