Blame SOURCES/virt-manager-virtinstall-Hide-total_size-in-the-progress-bar-if-it-doesn-t-need.patch

d80d1f
From 91cd135f66b517cf247d031966c2f33343c23aa3 Mon Sep 17 00:00:00 2001
d80d1f
From: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
d80d1f
Date: Wed, 9 Nov 2022 18:33:57 +0900
d80d1f
Subject: [PATCH] virtinstall: Hide total_size in the progress bar if it
d80d1f
 doesn't need
d80d1f
d80d1f
virt-install prints the total_size value to the progress bar even if it
d80d1f
is meaningless.
d80d1f
This value can be confusing to user, so for execute prosess that doesn't
d80d1f
copy files (total_size = 0B), we hide the total_size value.
d80d1f
For example, 'Creating domain...' doesn't need to print the total_size
d80d1f
value.
d80d1f
d80d1f
Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
d80d1f
Signed-off-by: Haruka Ohata <ohata.haruka@fujitsu.com>
d80d1f
(cherry picked from commit 6ec00474a659158f20248d6af3771d1a12ddac7b)
d80d1f
d80d1f
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2156247
d80d1f
d80d1f
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
d80d1f
---
d80d1f
 tests/data/meter/meter-zero.txt |  4 ++++
d80d1f
 tests/test_misc.py              | 14 ++++++++++++++
d80d1f
 virtinst/_progresspriv.py       |  8 ++++++--
d80d1f
 3 files changed, 24 insertions(+), 2 deletions(-)
d80d1f
 create mode 100644 tests/data/meter/meter-zero.txt
d80d1f
d80d1f
diff --git a/tests/data/meter/meter-zero.txt b/tests/data/meter/meter-zero.txt
d80d1f
new file mode 100644
d80d1f
index 000000000..fc81f21fd
d80d1f
--- /dev/null
d80d1f
+++ b/tests/data/meter/meter-zero.txt
d80d1f
@@ -0,0 +1,4 @@
d80d1f
+
d80d1f
+Meter text test            100% [================]    0 B/s |    0 B  --:-- ETA 
d80d1f
+
d80d1f
+Meter text test                                             |         00:02     
d80d1f
diff --git a/tests/test_misc.py b/tests/test_misc.py
d80d1f
index 20f5a626b..2cabc3382 100644
d80d1f
--- a/tests/test_misc.py
d80d1f
+++ b/tests/test_misc.py
d80d1f
@@ -224,6 +224,20 @@ def test_misc_meter():
d80d1f
     out = meter.output.getvalue().replace("\r", "\n")
d80d1f
     utils.diff_compare(out, os.path.join(utils.DATADIR, "meter", "meter6.txt"))
d80d1f
 
d80d1f
+    def _test_meter_zero(m, startval=0, text="Meter text test"):
d80d1f
+        with unittest.mock.patch("time.time", return_value=1.0):
d80d1f
+            m.start(text, startval)
d80d1f
+        with unittest.mock.patch("time.time", return_value=3.0):
d80d1f
+            m.update(0)
d80d1f
+        with unittest.mock.patch("time.time", return_value=3.1):
d80d1f
+            m.end()
d80d1f
+
d80d1f
+    # meter with size 0 and startval size 0
d80d1f
+    meter = _progresspriv.TextMeter(output=io.StringIO())
d80d1f
+    _test_meter_zero(meter, 0)
d80d1f
+    out = meter.output.getvalue().replace("\r", "\n")
d80d1f
+    utils.diff_compare(out, os.path.join(utils.DATADIR, "meter", "meter-zero.txt"))
d80d1f
+
d80d1f
     # BaseMeter coverage
d80d1f
     meter = _progresspriv.BaseMeter()
d80d1f
     _test_meter_values(meter)
d80d1f
diff --git a/virtinst/_progresspriv.py b/virtinst/_progresspriv.py
d80d1f
index a035c9c43..207c64796 100644
d80d1f
--- a/virtinst/_progresspriv.py
d80d1f
+++ b/virtinst/_progresspriv.py
d80d1f
@@ -247,11 +247,15 @@ class TextMeter(BaseMeter):
d80d1f
         tl = TerminalLine(8)
d80d1f
         # For big screens, make it more readable.
d80d1f
         use_hours = bool(tl.llen > 80)
d80d1f
-        ui_size = tl.add(' | %5sB' % total_size)
d80d1f
         ui_time = tl.add('  %s' % format_time(self.re.elapsed_time(),
d80d1f
                                               use_hours))
d80d1f
         ui_end, not_done = _term_add_end(tl, self.size, amount_read)
d80d1f
-        dummy = not_done
d80d1f
+        if not not_done and amount_read == 0:
d80d1f
+            # Doesn't need to print total_size
d80d1f
+            ui_size = tl.add(' | %5s ' % ' ')
d80d1f
+        else:
d80d1f
+            ui_size = tl.add(' | %5sB' % total_size)
d80d1f
+
d80d1f
         out = '\r%-*.*s%s%s%s\n' % (tl.rest(), tl.rest(), self.text,
d80d1f
                                     ui_size, ui_time, ui_end)
d80d1f
         self.output.write(out)
d80d1f
-- 
d80d1f
2.39.0
d80d1f