[PATCH 3/3] virtinstall: Hide total_size in the progress bar if it doesn't need

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
Signed-off-by: Haruka Ohata <ohata.haruka@xxxxxxxxxxx>
---
 tests/data/meter/meter9.txt |  4 ++++
 tests/test_misc.py          | 14 ++++++++++++++
 virtinst/_progresspriv.py   |  8 ++++++--
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 tests/data/meter/meter9.txt

diff --git a/tests/data/meter/meter9.txt b/tests/data/meter/meter9.txt
new file mode 100644
index 00000000..fc81f21f
--- /dev/null
+++ b/tests/data/meter/meter9.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 486d3d1e..57cd649c 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -191,6 +191,14 @@ def test_misc_meter():
         with unittest.mock.patch("time.time", return_value=1.3):
             m.end()
 
+    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, True)
+        with unittest.mock.patch("time.time", return_value=3.1):
+            m.end()
+
     # Basic output testing
     meter = _progresspriv.TextMeter(output=io.StringIO())
     _test_meter_values(meter)
@@ -245,6 +253,12 @@ def test_misc_meter():
     out = meter.output.getvalue().replace("\r", "\n")
     utils.diff_compare(out, os.path.join(utils.DATADIR, "meter", "meter8.txt"))
 
+    # 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", "meter9.txt"))
+
     # BaseMeter coverage
     meter = _progresspriv.BaseMeter()
     _test_meter_values(meter)
diff --git a/virtinst/_progresspriv.py b/virtinst/_progresspriv.py
index 119c4d2c..6572d669 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)
-- 
2.38.1




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux