summaryrefslogtreecommitdiff
path: root/virtinst/progress.py
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-10-11 12:35:55 +0100
committerCole Robinson <crobinso@redhat.com>2018-01-27 15:30:17 -0500
commit6712261510953f9c729624dded29bfffd32f88e6 (patch)
treebec6eb540f2870c26fc49a38c73e097b5d3c3c3b /virtinst/progress.py
parente9b4d35dd05c554a49301318e41076f07538a800 (diff)
downloadvirt-manager-6712261510953f9c729624dded29bfffd32f88e6.tar.gz
Python 2/3 division compatability
In Python 2 the classic devision of integers returns an integer but in Python 3 it might return float. Example: - Python 2: - Python 3: >>> 9 / 4 >>> 9 / 4 2 2.25 >>> 9 // 4 >>> 9 // 4 2 2 >>> 9 / 4.0 >>> 9 / 4.0 2.25 2.25 >>> 9 // 4.0 >>> 9 // 4.0 2.0 2.0 For more info see: https://www.python.org/dev/peps/pep-0238/
Diffstat (limited to 'virtinst/progress.py')
-rw-r--r--virtinst/progress.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/virtinst/progress.py b/virtinst/progress.py
index 2b070540..1cab0e8c 100644
--- a/virtinst/progress.py
+++ b/virtinst/progress.py
@@ -79,7 +79,7 @@ class TerminalLine:
a number of different elements (default=2). """
if self._llen < fixed:
return 0
- return (self._llen - fixed) / elements
+ return (self._llen - fixed) // elements
def add(self, element, full_len=None):
""" If there is room left in the line, above min_len, add element.
@@ -249,7 +249,7 @@ class TextMeter(BaseMeter):
sofar_size = None
if _text_meter_total_size:
sofar_size = _text_meter_sofar_size + amount_read
- sofar_pc = (sofar_size * 100) / _text_meter_total_size
+ sofar_pc = (sofar_size * 100) // _text_meter_total_size
# Include text + ui_rate in minimal
tl = TerminalLine(8, 8+1+8)
@@ -385,7 +385,7 @@ class RateEstimator:
(can be None for unknown transfer size)"""
if self.total is None: return None
elif self.total == 0: return 1.0
- else: return float(self.last_amount_read)/self.total
+ else: return float(self.last_amount_read) / self.total
#########################################################################
# support methods
@@ -432,7 +432,7 @@ class RateEstimator:
"""
if rt < 0: return 0.0
- shift = int(math.log(rt/start_time)/math.log(2))
+ shift = int(math.log(rt / start_time) / math.log(2))
rt = int(rt)
if shift <= 0: return rt
return float(int(rt) >> shift << shift)
@@ -446,10 +446,10 @@ def format_time(seconds, use_hours=0):
return 'Infinite'
else:
seconds = int(seconds)
- minutes = seconds / 60
+ minutes = seconds // 60
seconds = seconds % 60
if use_hours:
- hours = minutes / 60
+ hours = minutes // 60
minutes = minutes % 60
return '%02i:%02i:%02i' % (hours, minutes, seconds)
else: