From 72ef1969d801707cf6e3c2073b57b34f66e6794f Mon Sep 17 00:00:00 2001
From: mulhern <amulhern@redhat.com>
Date: Thu, 24 Apr 2014 11:48:17 -0400
Subject: [PATCH 15/28] Updates for new blivet.size.Size.__new__ interface.

Remove uses of SizeParamsError since it is no longer used.

Signed-off-by: mulhern <amulhern@redhat.com>
(cherry picked from commit 7adff668080bcec9de4f7f6fa75bebca5975bcbd)
---
 pyanaconda/bootloader.py                 |  4 ++--
 pyanaconda/installclass.py               |  8 +++----
 pyanaconda/kickstart.py                  | 30 ++++++++++++++++----------
 pyanaconda/packaging/livepayload.py      |  6 +++---
 pyanaconda/packaging/rpmostreepayload.py |  2 +-
 pyanaconda/packaging/yumpayload.py       |  4 ++--
 pyanaconda/ui/gui/spokes/custom.py       | 17 +++++++--------
 pyanaconda/ui/gui/spokes/lib/cart.py     |  8 +++----
 pyanaconda/ui/gui/spokes/lib/resize.py   | 36 ++++++++++++++++----------------
 pyanaconda/ui/gui/spokes/storage.py      | 10 ++++-----
 pyanaconda/ui/lib/space.py               |  4 ++--
 pyanaconda/ui/tui/spokes/storage.py      |  4 ++--
 12 files changed, 70 insertions(+), 63 deletions(-)

diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py
index f1229cd..2a994e2 100644
--- a/pyanaconda/bootloader.py
+++ b/pyanaconda/bootloader.py
@@ -244,7 +244,7 @@ class BootLoader(object):
     stage2_bootable = False
     stage2_must_be_primary = True
     stage2_description = N_("/boot file system")
-    stage2_max_end = Size(spec="2 TiB")
+    stage2_max_end = Size("2 TiB")
 
     @property
     def stage2_format_types(self):
@@ -493,7 +493,7 @@ class BootLoader(object):
         if max_end and device.type == "partition" and device.partedPartition:
             end_sector = device.partedPartition.geometry.end
             sector_size = device.partedPartition.disk.device.sectorSize
-            end = Size(bytes=sector_size * end_sector)
+            end = Size(sector_size * end_sector)
             if end > max_end:
                 self.errors.append(_("%(desc)s must be within the first %(max_end)s of "
                                      "the disk.") % {"desc": desc, "max_end": max_end})
diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py
index 9ffaa14..3b8811b 100644
--- a/pyanaconda/installclass.py
+++ b/pyanaconda/installclass.py
@@ -81,14 +81,14 @@ class BaseInstallClass(object):
 
     def setDefaultPartitioning(self, storage):
         autorequests = [PartSpec(mountpoint="/", fstype=storage.defaultFSType,
-                                 size=Size(spec="1GiB"),
-                                 maxSize=Size(spec="50GiB"),
+                                 size=Size("1GiB"),
+                                 maxSize=Size("50GiB"),
                                  grow=True,
                                  btr=True, lv=True, thin=True, encrypted=True),
                         PartSpec(mountpoint="/home",
                                  fstype=storage.defaultFSType,
-                                 size=Size(spec="500MiB"), grow=True,
-                                 requiredSpace=Size(spec="50GiB"),
+                                 size=Size("500MiB"), grow=True,
+                                 requiredSpace=Size("50GiB"),
                                  btr=True, lv=True, thin=True, encrypted=True)]
 
         bootreqs = platform.setDefaultPartitioning()
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 63d2611..c469134 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -757,9 +757,11 @@ class LogVolData(commands.logvol.F20_LogVolData):
         vgname = ksdata.onPart.get(self.vgname, self.vgname)
 
         try:
-            size = Size(spec="%d MiB" % self.size)
-        except Exception:
+            size = Size("%d MiB" % self.size)
+        except ValueError:
             raise KickstartValueError(formatErrorMsg(self.lineno, msg="The size %s is not valid." % self.size))
+        except TypeError:
+            pass
 
         if self.mountpoint == "swap":
             ty = "swap"
@@ -890,16 +892,18 @@ class LogVolData(commands.logvol.F20_LogVolData):
                 parents = [vg]
 
             if self.thin_pool:
-                pool_args = { "metadatasize": Size(spec="%d MiB" % self.metadata_size),
-                              "chunksize": Size(spec="%d KiB" % self.chunk_size) }
+                pool_args = { "metadatasize": Size("%d MiB" % self.metadata_size),
+                              "chunksize": Size("%d KiB" % self.chunk_size) }
             else:
                 pool_args = {}
 
             if self.maxSizeMB:
                 try:
-                    maxsize = Size(spec="%d MiB" % self.maxSizeMB)
-                except Exception:
+                    maxsize = Size("%d MiB" % self.maxSizeMB)
+                except ValueError:
                     raise KickstartValueError(formatErrorMsg(self.lineno, msg="The maximum size %s is not valid." % self.maxSizeMB))
+                except TypeError:
+                    pass
             else:
                 maxsize = None
 
@@ -987,9 +991,11 @@ class PartitionData(commands.partition.F18_PartData):
         storage.doAutoPart = False
 
         try:
-            size = Size(spec="%d MiB" % self.size)
-        except Exception:
+            size = Size("%d MiB" % self.size)
+        except ValueError:
             raise KickstartValueError(formatErrorMsg(self.lineno, msg="The size %s is not valid." % self.size))
+        except TypeError:
+            pass
 
         if self.onbiosdisk != "":
             for (disk, biosdisk) in storage.eddDict.iteritems():
@@ -1140,9 +1146,11 @@ class PartitionData(commands.partition.F18_PartData):
         kwargs["size"] = size
         if self.maxSizeMB:
             try:
-                maxsize = Size(spec="%d MiB" % self.maxSizeMB)
-            except Exception:
+                maxsize = Size("%d MiB" % self.maxSizeMB)
+            except ValueError:
                 raise KickstartValueError(formatErrorMsg(self.lineno, msg="The maximum size %s is not valid." % self.maxSizeMB))
+            except TypeError:
+                pass
         else:
             maxsize = None
 
@@ -1541,7 +1549,7 @@ class VolGroupData(commands.volgroup.RHEL7_VolGroupData):
             # default PE size requested -- we use blivet's default in KiB
             self.pesize = LVM_PE_SIZE * 1024
 
-        pesize = Size(spec="%d KiB" % self.pesize)
+        pesize = Size("%d KiB" % self.pesize)
         if pesize not in getPossiblePhysicalExtents(floor=1024):
             raise KickstartValueError(formatErrorMsg(self.lineno, msg="Volume group specified invalid pesize"))
 
diff --git a/pyanaconda/packaging/livepayload.py b/pyanaconda/packaging/livepayload.py
index a95ac42..f82bfb3 100644
--- a/pyanaconda/packaging/livepayload.py
+++ b/pyanaconda/packaging/livepayload.py
@@ -171,7 +171,7 @@ class LiveImagePayload(ImagePayload):
 
     @property
     def spaceRequired(self):
-        return Size(bytes=iutil.getDirSize("/")*1024)
+        return Size(iutil.getDirSize("/")*1024)
 
 class URLGrabberProgress(object):
     """ Provide methods for urlgrabber progress."""
@@ -420,6 +420,6 @@ class LiveImageKSPayload(LiveImagePayload):
             and install.
         """
         if self._min_size:
-            return Size(bytes=self._min_size)
+            return Size(self._min_size)
         else:
-            return Size(bytes=1024*1024*1024)
+            return Size(1024*1024*1024)
diff --git a/pyanaconda/packaging/rpmostreepayload.py b/pyanaconda/packaging/rpmostreepayload.py
index ae5ad08..0905419 100644
--- a/pyanaconda/packaging/rpmostreepayload.py
+++ b/pyanaconda/packaging/rpmostreepayload.py
@@ -56,7 +56,7 @@ class RPMOSTreePayload(ArchivePayload):
     @property
     def spaceRequired(self):
         # We don't have this data with OSTree at the moment
-        return Size(spec="500 MB")
+        return Size("500 MB")
 
     def _safeExecWithRedirect(self, cmd, argv, **kwargs):
         """Like iutil.execWithRedirect, but treat errors as fatal"""
diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
index 58e9281..7fa8b2e 100644
--- a/pyanaconda/packaging/yumpayload.py
+++ b/pyanaconda/packaging/yumpayload.py
@@ -193,7 +193,7 @@ class YumPayload(PackagePayload):
         # This value comes from a default install of the x86_64 Fedora 18.  It
         # is meant as a best first guess only.  Once package metadata is
         # available we can use that as a better value.
-        self._space_required = Size(spec="3000 MB")
+        self._space_required = Size("3000 MB")
 
         self._resetYum(root=root, releasever=releasever)
 
@@ -1357,7 +1357,7 @@ reposdir=%s
 
         total += total * 0.35   # add 35% to account for the fact that the above
                                 # method is laughably inaccurate
-        self._space_required = Size(bytes=total)
+        self._space_required = Size(total)
 
         return self._space_required
 
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index c6afd73..9deb4c7 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -65,7 +65,6 @@ from blivet.errors import NotEnoughFreeSpaceError
 from blivet.errors import SanityError
 from blivet.errors import SanityWarning
 from blivet.errors import LUKSDeviceWithoutKeyError
-from blivet.errors import SizeParamsError
 from blivet.devicelibs import mdraid
 from blivet.devices import LUKSDevice
 
@@ -192,13 +191,13 @@ def size_from_entry(entry):
         size_text += "MB"
 
     try:
-        size = Size(spec=size_text)
-    except (SizeParamsError, ValueError):
+        size = Size(size_text)
+    except ValueError:
         return None
     else:
         # Minimium size for ui-created partitions is 1MiB.
         if size.convertTo(spec="MiB") < 1:
-            size = Size(spec="1 MiB")
+            size = Size("1 MiB")
 
     return size
 
@@ -292,7 +291,7 @@ class AddDialog(GUIObject):
     def __init__(self, *args, **kwargs):
         self.mountpoints = kwargs.pop("mountpoints", [])
         GUIObject.__init__(self, *args, **kwargs)
-        self.size = Size(bytes=0)
+        self.size = Size(0)
         self.mountpoint = ""
         self._error = False
 
@@ -446,7 +445,7 @@ class ContainerDialog(GUIObject):
         self.exists = kwargs.pop("exists", False)
 
         self.size_policy = kwargs.pop("size_policy", SIZE_POLICY_AUTO)
-        self.size = kwargs.pop("size", Size(bytes=0))
+        self.size = kwargs.pop("size", Size(0))
 
         self._error = None
         GUIObject.__init__(self, *args, **kwargs)
@@ -675,7 +674,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         self._error = None
         self._media_disks = []
         self._fs_types = []             # list of supported fstypes
-        self._free_space = Size(bytes=0)
+        self._free_space = Size(0)
 
         self._device_disks = []
         self._device_container_name = None
@@ -834,8 +833,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
 
     def _currentTotalSpace(self):
         """Add up the sizes of all selected disks and return it as a Size."""
-        totalSpace = sum(disk.size for disk in self._clearpartDevices,
-                         Size(bytes=0))
+        totalSpace = sum((disk.size for disk in self._clearpartDevices),
+                         Size(0))
         return totalSpace
 
     def _updateSpaceDisplay(self):
diff --git a/pyanaconda/ui/gui/spokes/lib/cart.py b/pyanaconda/ui/gui/spokes/lib/cart.py
index b62c0eb..72e28ad 100644
--- a/pyanaconda/ui/gui/spokes/lib/cart.py
+++ b/pyanaconda/ui/gui/spokes/lib/cart.py
@@ -124,11 +124,11 @@ class SelectedDisksDialog(GUIObject):
         free = 0
         for row in self._store:
             count += 1
-            size += Size(spec=row[SIZE_COL])
-            free += Size(spec=row[FREE_SPACE_COL])
+            size += Size(row[SIZE_COL])
+            free += Size(row[FREE_SPACE_COL])
 
-        size = str(Size(bytes=long(size))).upper()
-        free = str(Size(bytes=long(free))).upper()
+        size = str(Size(long(size))).upper()
+        free = str(Size(long(free))).upper()
 
         text = P_("<b>%(count)s disk; %(size)s capacity; %(free)s free space</b> "
                    "(unpartitioned and in file systems)",
diff --git a/pyanaconda/ui/gui/spokes/lib/resize.py b/pyanaconda/ui/gui/spokes/lib/resize.py
index 2eb755a..ffb2a91 100644
--- a/pyanaconda/ui/gui/spokes/lib/resize.py
+++ b/pyanaconda/ui/gui/spokes/lib/resize.py
@@ -66,8 +66,8 @@ class ResizeDialog(GUIObject):
         self.storage = storage
         self.payload = payload
 
-        self._initialFreeSpace = Size(bytes=0)
-        self._selectedReclaimableSpace = Size(bytes=0)
+        self._initialFreeSpace = Size(0)
+        self._selectedReclaimableSpace = Size(0)
 
         self._actionStore = self.builder.get_object("actionStore")
         self._diskStore = self.builder.get_object("diskStore")
@@ -118,10 +118,10 @@ class ResizeDialog(GUIObject):
 
     def populate(self, disks):
         totalDisks = 0
-        totalReclaimableSpace = Size(bytes=0)
+        totalReclaimableSpace = Size(0)
 
-        self._initialFreeSpace = Size(bytes=0)
-        self._selectedReclaimableSpace = Size(bytes=0)
+        self._initialFreeSpace = Size(0)
+        self._selectedReclaimableSpace = Size(0)
 
         canShrinkSomething = False
 
@@ -133,7 +133,7 @@ class ResizeDialog(GUIObject):
 
             if disk.partitioned:
                 fstype = ""
-                diskReclaimableSpace = Size(bytes=0)
+                diskReclaimableSpace = Size(0)
             else:
                 fstype = disk.format.type
                 diskReclaimableSpace = disk.size
@@ -186,7 +186,7 @@ class ResizeDialog(GUIObject):
             # And then add another uneditable line that lists how much space is
             # already free in the disk.
             diskFree = free_space[disk.name][0]
-            if diskFree >= Size(spec="1MiB"):
+            if diskFree >= Size("1MiB"):
                 self._diskStore.append(itr, [disk.id,
                                              _("""<span foreground='grey' style='italic'>Free space</span>"""),
                                              "",
@@ -247,9 +247,9 @@ class ResizeDialog(GUIObject):
         # The slider needs to be keyboard-accessible.  We'll make small movements change in
         # 1% increments, and large movements in 5% increments.
         distance = device.size - device.minSize
-        onePercent = Size(bytes=distance / 100)
-        fivePercent = Size(bytes=distance / 20)
-        twentyPercent = Size(bytes=distance / 5)
+        onePercent = Size(distance / 100)
+        fivePercent = Size(distance / 20)
+        twentyPercent = Size(distance / 5)
 
         adjustment = self.builder.get_object("resizeAdjustment")
         adjustment.configure(value, int(ceil(device.minSize)), int(device.size), onePercent, fivePercent, 0)
@@ -282,7 +282,7 @@ class ResizeDialog(GUIObject):
         self._shrinkButton.set_sensitive(device.resizable)
 
         if device.resizable:
-            self._setup_slider(device, Size(bytes=obj.target))
+            self._setup_slider(device, Size(obj.target))
 
         # Then, disable the button for whatever action is currently selected.
         # It doesn't make a lot of sense to allow clicking that.
@@ -332,7 +332,7 @@ class ResizeDialog(GUIObject):
         if obj.action == _(PRESERVE):
             return False
         if obj.action == _(SHRINK):
-            self._selectedReclaimableSpace += device.size - Size(bytes=obj.target)
+            self._selectedReclaimableSpace += device.size - Size(obj.target)
         elif obj.action == _(DELETE):
             self._selectedReclaimableSpace += int(device.size)
 
@@ -386,7 +386,7 @@ class ResizeDialog(GUIObject):
 
         # And then we're keeping a running tally of how much space the user
         # has selected to reclaim, so reflect that in the UI.
-        self._selectedReclaimableSpace = Size(bytes=0)
+        self._selectedReclaimableSpace = Size(0)
         self._diskStore.foreach(self._sumReclaimableSpace, None)
         self._update_labels(selectedReclaimable=self._selectedReclaimableSpace)
 
@@ -421,7 +421,7 @@ class ResizeDialog(GUIObject):
         elif obj.action == _(SHRINK):
             if device.resizable:
                 # round this up to nearest MB? MiB? Maybe in targetSize setter.
-                self.storage.resizeDevice(device, Size(bytes=obj.target))
+                self.storage.resizeDevice(device, Size(obj.target))
             else:
                 self._recursiveRemove(device)
         elif obj.action == _(DELETE):
@@ -477,14 +477,14 @@ class ResizeDialog(GUIObject):
     def on_resize_value_changed(self, rng):
         (model, itr) = self._selection.get_selected()
 
-        old_delta = Size(bytes=rng.get_adjustment().get_upper()) - int(model[itr][RESIZE_TARGET_COL])
+        old_delta = Size(rng.get_adjustment().get_upper()) - int(model[itr][RESIZE_TARGET_COL])
         self._selectedReclaimableSpace -= old_delta
 
         # Update the target size in the store.
-        model[itr][RESIZE_TARGET_COL] = Size(bytes=rng.get_value())
+        model[itr][RESIZE_TARGET_COL] = Size(rng.get_value())
 
         # Update the "Total selected space" label.
-        delta = Size(bytes=rng.get_adjustment().get_upper()) - int(rng.get_value())
+        delta = Size(rng.get_adjustment().get_upper()) - int(rng.get_value())
         self._selectedReclaimableSpace += delta
         self._update_labels(selectedReclaimable=self._selectedReclaimableSpace)
 
@@ -494,4 +494,4 @@ class ResizeDialog(GUIObject):
     def resize_slider_format(self, scale, value):
         # This makes the value displayed under the slider prettier than just a
         # single number.
-        return str(Size(bytes=value))
+        return str(Size(value))
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index 07be194..366291d 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -641,8 +641,8 @@ class StorageSpoke(NormalSpoke, StorageChecker):
     def _update_summary(self):
         """ Update the summary based on the UI. """
         count = 0
-        capacity = Size(bytes=0)
-        free = Size(bytes=0)
+        capacity = Size(0)
+        free = Size(0)
 
         # pass in our disk list so hidden disks' free space is available
         free_space = self.storage.getFreeSpace(disks=self.disks)
@@ -797,7 +797,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
 
         # show the installation options dialog
         disks = [d for d in self.disks if d.name in self.selected_disks]
-        disks_size = sum(d.size for d in disks, Size(bytes=0))
+        disks_size = sum((d.size for d in disks), Size(0))
 
         # No disks selected?  The user wants to back out of the storage spoke.
         if not disks:
@@ -847,8 +847,8 @@ class StorageSpoke(NormalSpoke, StorageChecker):
             fs_free = sum(f[1] for f in free_space.itervalues())
 
         required_space = self.payload.spaceRequired
-        auto_swap = sum(r.size for r in self.storage.autoPartitionRequests
-                                if r.fstype == "swap", Size(bytes=0))
+        auto_swap = sum((r.size for r in self.storage.autoPartitionRequests
+                                if r.fstype == "swap"), Size(0))
 
         log.debug("disk free: %s  fs free: %s  sw needs: %s  auto swap: %s",
                   disk_free, fs_free, required_space, auto_swap)
diff --git a/pyanaconda/ui/lib/space.py b/pyanaconda/ui/lib/space.py
index 8356dab..f64581b 100644
--- a/pyanaconda/ui/lib/space.py
+++ b/pyanaconda/ui/lib/space.py
@@ -55,7 +55,7 @@ class FileSystemSpaceChecker(object):
            check again.
         """
         self.success = False
-        self.deficit = Size(bytes=0)
+        self.deficit = Size(0)
         self.error_message = ""
 
     def check(self):
@@ -72,7 +72,7 @@ class FileSystemSpaceChecker(object):
                             in the info bar at the bottom of a Hub.
         """
         self.reset()
-        free = Size(bytes=self.storage.fileSystemFreeSpace)
+        free = Size(self.storage.fileSystemFreeSpace)
         needed = self.payload.spaceRequired
         log.info("fs space: %s  needed: %s", free, needed)
         self.success = (free >= needed)
diff --git a/pyanaconda/ui/tui/spokes/storage.py b/pyanaconda/ui/tui/spokes/storage.py
index 76af5a8..9719fd8 100644
--- a/pyanaconda/ui/tui/spokes/storage.py
+++ b/pyanaconda/ui/tui/spokes/storage.py
@@ -152,7 +152,7 @@ class StorageSpoke(NormalTUISpoke):
         """ Update the summary based on the UI. """
         count = 0
         capacity = 0
-        free = Size(bytes=0)
+        free = Size(0)
 
         # pass in our disk list so hidden disks' free space is available
         free_space = self.storage.getFreeSpace(disks=self.disks)
@@ -165,7 +165,7 @@ class StorageSpoke(NormalTUISpoke):
 
         summary = (P_(("%d disk selected; %s capacity; %s free ..."),
                       ("%d disks selected; %s capacity; %s free ..."),
-                      count) % (count, str(Size(bytes=capacity)), free))
+                      count) % (count, str(Size(capacity)), free))
 
         if len(self.disks) == 0:
             summary = _("No disks detected.  Please shut down the computer, connect at least one disk, and restart to complete installation.")
-- 
1.9.3

