[anaconda:master 1/2] Make size_from_input() and size_from_entry() methods handier.

mulhern amulhern at redhat.com
Thu Oct 16 22:45:34 UTC 2014


* In size_from_input(), do not round up to any lower bound, just get the
size. It's more general that way.
* Parameterize size_from_entry() on a lower bound.
* Add method docstrings.

Should not change any observable behavior, as size_from_input() seems to
be only invoked by size_from_entry() method.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 pyanaconda/storage_utils.py                         | 13 ++++++++-----
 .../ui/gui/spokes/lib/custom_storage_helpers.py     | 21 +++++++++++++++++++--
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/pyanaconda/storage_utils.py b/pyanaconda/storage_utils.py
index 7d26e78..16a1d5a 100644
--- a/pyanaconda/storage_utils.py
+++ b/pyanaconda/storage_utils.py
@@ -91,7 +91,14 @@ NAMED_DEVICE_TYPES = (DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM, DEVICE_TYPE_MD, DEVICE
 CONTAINER_DEVICE_TYPES = (DEVICE_TYPE_LVM, DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM_THINP)
 
 def size_from_input(input_str):
-    """Get size from user's input"""
+    """ Get a Size object from an input string.
+
+        :param str input_str: a string forming some representation of a size
+        :returns: a Size object corresponding to input_str
+        :rtype: :class:`blivet.size.Size` or NoneType
+
+        If no units specified, defaults to MiB.
+    """
 
     if not input_str:
         # Nothing to parse
@@ -106,10 +113,6 @@ def size_from_input(input_str):
         size = Size(input_str)
     except ValueError:
         return None
-    else:
-        # Minimium size for ui-created partitions is 1MiB.
-        if size.convertTo(spec="MiB") < 1:
-            size = Size("1 MiB")
 
     return size
 
diff --git a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
index 4d0948c..a6a2263 100644
--- a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
+++ b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
@@ -78,9 +78,26 @@ CONTAINER_TYPES = {DEVICE_TYPE_LVM:       ContainerType(N_("Volume Group"), N_("
 # These cannot be specified as mountpoints
 system_mountpoints = ["/dev", "/proc", "/run", "/sys"]
 
-def size_from_entry(entry):
+def size_from_entry(entry, lower_bound=Size("1 MiB")):
+    """ Get a Size object from an entry field.
+
+        :param lower_bound: lower bound for size returned,
+        :type lower_bound: :class:`blivet.size.Size` or NoneType
+        :returns: a Size object corresponding to the text in the entry field
+        :rtype: :class:`blivet.size.Size` or NoneType
+
+        If no units specified in the field, defaults to MiB.
+
+        Rounds up to lower_bound, if value in entry field corresponds
+        to a smaller value. The default for lower_bound is 1 MiB.
+    """
     size_text = entry.get_text().decode("utf-8").strip()
-    return size_from_input(size_text)
+    size = size_from_input(size_text)
+    if size is None:
+        return None
+    if lower_bound is not None and size < lower_bound:
+        return lower_bound
+    return size
 
 def populate_mountpoint_store(store, used_mountpoints):
     # sure, add whatever you want to this list. this is just a start.
-- 
1.9.3



More information about the anaconda-patches mailing list