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

[PATCH master] Return values, not strings



returning strings to insert into other strings makes it harder to
translate so use the return value to select the correct string.
---
 pyanaconda/storage/__init__.py     |    9 ++++++-
 pyanaconda/storage/devices.py      |   39 +++++++++++++++++++----------------
 pyanaconda/storage/partitioning.py |   10 +++++++-
 3 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index b000573..11f2acf 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -1104,8 +1104,13 @@ class Storage(object):
 
         for (mount, device) in filesystems.items():
             problem = filesystems[mount].checkSize()
-            if problem:
-                errors.append(_("Your %s partition is too %s for %s formatting "
+            if problem < 0:
+                errors.append(_("Your %s partition is too small for %s formatting "
+                                "(allowable size is %d MB to %d MB)")
+                              % (mount, problem, device.format.name,
+                                 device.minSize, device.maxSize))
+            elif problem > 0:
+                errors.append(_("Your %s partition is too large for %s formatting "
                                 "(allowable size is %d MB to %d MB)")
                               % (mount, problem, device.format.name,
                                  device.minSize, device.maxSize))
diff --git a/pyanaconda/storage/devices.py b/pyanaconda/storage/devices.py
index 303856b..017d48c 100644
--- a/pyanaconda/storage/devices.py
+++ b/pyanaconda/storage/devices.py
@@ -936,15 +936,16 @@ class StorageDevice(Device):
         """ Check to make sure the size of the device is allowed by the
             format used.
 
-            return None is all is ok
-            return large or small depending on the problem
+            Returns:
+            0  - ok
+            1  - Too large
+            -1 - Too small
         """
-        problem = None
         if self.format.maxSize and self.size > self.format.maxSize:
-            problem = _("large")
+            return 1
         elif self.format.minSize and self.size < self.format.minSize:
-            problem = _("small")
-        return problem
+            return -1
+        return 0
 
 class DiskDevice(StorageDevice):
     """ A disk """
@@ -1612,19 +1613,20 @@ class PartitionDevice(StorageDevice):
         """ Check to make sure the size of the device is allowed by the
             format used.
 
-            return None is all is ok
-            return large or small depending on the problem
+            Returns:
+            0  - ok
+            1  - Too large
+            -1 - Too small
         """
-        problem = None
         if self.format.maxSize and self.size > self.format.maxSize:
-            problem = _("large")
+            return 1
         elif (self.format.minSize and
               (not self.req_grow and
                self.size < self.format.minSize) or
               (self.req_grow and self.req_max_size and
                self.req_max_size < self.format.minSize)):
-            problem = _("small")
-        return problem
+            return -1
+        return 0
 
 class DMDevice(StorageDevice):
     """ A device-mapper device """
@@ -2588,19 +2590,20 @@ class LVMLogicalVolumeDevice(DMDevice):
         """ Check to make sure the size of the device is allowed by the
             format used.
 
-            return None is all is ok
-            return large or small depending on the problem
+            Returns:
+            0  - ok
+            1  - Too large
+            -1 - Too small
         """
-        problem = None
         if self.format.maxSize and self.size > self.format.maxSize:
-            problem = _("large")
+            return 1
         elif (self.format.minSize and
               (not self.req_grow and
                self.size < self.format.minSize) or
               (self.req_grow and self.req_max_size and
                self.req_max_size < self.format.minSize)):
-            problem = _("small")
-        return problem
+            return -1
+        return 0
 
 class MDRaidArrayDevice(StorageDevice):
     """ An mdraid (Linux RAID) device. """
diff --git a/pyanaconda/storage/partitioning.py b/pyanaconda/storage/partitioning.py
index aebd7b8..a699125 100644
--- a/pyanaconda/storage/partitioning.py
+++ b/pyanaconda/storage/partitioning.py
@@ -1001,8 +1001,14 @@ def allocatePartitions(storage, disks, partitions, freespace, bootloader=None):
                 current_free = None
 
             problem = _part.checkSize()
-            if problem:
-                raise PartitioningError("partition is too %s for %s formatting "
+            if problem < 0:
+                raise PartitioningError("partition is too small for %s formatting "
+                                        "(allowable size is %d MB to %d MB)"
+                                        % (problem, _part.format.name,
+                                           _part.format.minSize,
+                                           _part.format.maxSize))
+            elif problem > 0:
+                raise PartitioningError("partition is too large for %s formatting "
                                         "(allowable size is %d MB to %d MB)"
                                         % (problem, _part.format.name,
                                            _part.format.minSize,
-- 
1.7.4


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