[blivet:rhel7-master 3/3] Condense and comment sanitize_dasd_dev_input (#1070115)

mulhern amulhern at redhat.com
Mon Sep 8 17:27:27 UTC 2014


Related: rhbz#1070115

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicelibs/dasd.py | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/blivet/devicelibs/dasd.py b/blivet/devicelibs/dasd.py
index b558fef..b24add7 100644
--- a/blivet/devicelibs/dasd.py
+++ b/blivet/devicelibs/dasd.py
@@ -109,22 +109,28 @@ def dasd_needs_format(dasd):
     return False
 
 def sanitize_dasd_dev_input(dev):
-    """ Given a user-supplied device number, make sure the input is sane, and
-        raise an error if it is not.
+    """ Synthesizes a complete DASD number from a possibly partial one.
 
-    :param dev: string representing a DASD device number
+        :param str dev: string representing a DASD device number
+        :returns: a synthesized DASD device number
+        :rtype: str
+
+        :raises: ValueError if dev is None or empty
+
+        *) Assumes that the rightmost '.' if any, separates the bus number
+           from the device number.
+        *) Pads the device number on the left with 0s to a length of four
+           characters.
+        *) If no bus number extracted from dev, uses bus number default 0.0.
     """
     if dev is None or dev == "":
         raise ValueError(_("You have not specified a device number or the number is invalid"))
     dev = dev.lower()
-    bus = dev[:dev.rfind(".") + 1]
-    dev = dev[dev.rfind(".") + 1:]
-
-    dev = "0" * (4 - len(dev)) + dev
-    if not bus:
-        return "0.0." + dev
-    else:
-        return bus + dev
+    (bus, _sep, dev) = dev.rpartition('.')
+
+    padding = "0" * (4 - len(dev))
+    bus = bus or '0.0'
+    return bus + '.' + padding + dev
 
 def online_dasd(dev):
     """ Given a device number, switch the device to be online.
-- 
1.9.3



More information about the anaconda-patches mailing list