[PATCH 1/7] Make sure doing math on Size instances yields Size values.

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

 



Previously we were ending up with Decimal any time we added
two Size values together.
---
 pyanaconda/storage/size.py |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/pyanaconda/storage/size.py b/pyanaconda/storage/size.py
index 8512b45..865634c 100644
--- a/pyanaconda/storage/size.py
+++ b/pyanaconda/storage/size.py
@@ -142,6 +142,21 @@ class Size(Decimal):
     def __str__(self):
         return self.humanReadable()
 
+    def __repr__(self):
+        return "Size('%s')" % self
+
+    def __add__(self, other):
+        return Size(bytes=Decimal.__add__(self, other))
+
+    def __sub__(self, other):
+        return Size(bytes=Decimal.__sub__(self, other))
+
+    def __mul__(self, other):
+        return Size(bytes=Decimal.__mul__(self, other))
+
+    def __div__(self, other):
+        return Size(bytes=Decimal.__div__(self, other))
+
     def _trimEnd(self, val):
         """ Internal method to trim trailing zeros. """
         val = re.sub(r'(\.\d*?)0+$', '\\1', val)
@@ -187,7 +202,7 @@ class Size(Decimal):
             return "%s b" % check
 
         for factor, prefix, abbr in _prefixes:
-            newcheck = self / Decimal(factor)
+            newcheck = super(Size, self).__div__(Decimal(factor))
 
             if newcheck < 1000:
                 if places is not None:
-- 
1.7.7.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux