73 lines
3.0 KiB
Diff
73 lines
3.0 KiB
Diff
Subject: virtinstall: Hide total_size in the progress bar if it doesn't need
|
|
From: Toshiki Sonoda sonoda.toshiki@fujitsu.com Wed Nov 9 18:33:57 2022 +0900
|
|
Date: Wed Dec 14 13:18:36 2022 -0500:
|
|
Git: 6ec00474a659158f20248d6af3771d1a12ddac7b
|
|
|
|
virt-install prints the total_size value to the progress bar even if it
|
|
is meaningless.
|
|
This value can be confusing to user, so for execute prosess that doesn't
|
|
copy files (total_size = 0B), we hide the total_size value.
|
|
For example, 'Creating domain...' doesn't need to print the total_size
|
|
value.
|
|
|
|
Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
|
|
Signed-off-by: Haruka Ohata <ohata.haruka@fujitsu.com>
|
|
|
|
diff --git a/tests/data/meter/meter-zero.txt b/tests/data/meter/meter-zero.txt
|
|
new file mode 100644
|
|
index 00000000..fc81f21f
|
|
--- /dev/null
|
|
+++ b/tests/data/meter/meter-zero.txt
|
|
@@ -0,0 +1,4 @@
|
|
+
|
|
+Meter text test 100% [================] 0 B/s | 0 B --:-- ETA
|
|
+
|
|
+Meter text test | 00:02
|
|
diff --git a/tests/test_misc.py b/tests/test_misc.py
|
|
index 20f5a626..2cabc338 100644
|
|
--- a/tests/test_misc.py
|
|
+++ b/tests/test_misc.py
|
|
@@ -224,6 +224,20 @@ def test_misc_meter():
|
|
out = meter.output.getvalue().replace("\r", "\n")
|
|
utils.diff_compare(out, os.path.join(utils.DATADIR, "meter", "meter6.txt"))
|
|
|
|
+ def _test_meter_zero(m, startval=0, text="Meter text test"):
|
|
+ with unittest.mock.patch("time.time", return_value=1.0):
|
|
+ m.start(text, startval)
|
|
+ with unittest.mock.patch("time.time", return_value=3.0):
|
|
+ m.update(0)
|
|
+ with unittest.mock.patch("time.time", return_value=3.1):
|
|
+ m.end()
|
|
+
|
|
+ # meter with size 0 and startval size 0
|
|
+ meter = _progresspriv.TextMeter(output=io.StringIO())
|
|
+ _test_meter_zero(meter, 0)
|
|
+ out = meter.output.getvalue().replace("\r", "\n")
|
|
+ utils.diff_compare(out, os.path.join(utils.DATADIR, "meter", "meter-zero.txt"))
|
|
+
|
|
# BaseMeter coverage
|
|
meter = _progresspriv.BaseMeter()
|
|
_test_meter_values(meter)
|
|
diff --git a/virtinst/_progresspriv.py b/virtinst/_progresspriv.py
|
|
index a035c9c4..207c6479 100644
|
|
--- a/virtinst/_progresspriv.py
|
|
+++ b/virtinst/_progresspriv.py
|
|
@@ -247,11 +247,15 @@ class TextMeter(BaseMeter):
|
|
tl = TerminalLine(8)
|
|
# For big screens, make it more readable.
|
|
use_hours = bool(tl.llen > 80)
|
|
- ui_size = tl.add(' | %5sB' % total_size)
|
|
ui_time = tl.add(' %s' % format_time(self.re.elapsed_time(),
|
|
use_hours))
|
|
ui_end, not_done = _term_add_end(tl, self.size, amount_read)
|
|
- dummy = not_done
|
|
+ if not not_done and amount_read == 0:
|
|
+ # Doesn't need to print total_size
|
|
+ ui_size = tl.add(' | %5s ' % ' ')
|
|
+ else:
|
|
+ ui_size = tl.add(' | %5sB' % total_size)
|
|
+
|
|
out = '\r%-*.*s%s%s%s\n' % (tl.rest(), tl.rest(), self.text,
|
|
ui_size, ui_time, ui_end)
|
|
self.output.write(out)
|