[PATCH] Put the lv checks in inner functions.

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

 



---
 iw/lvm_dialog_gui.py |  168 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 109 insertions(+), 59 deletions(-)

diff --git a/iw/lvm_dialog_gui.py b/iw/lvm_dialog_gui.py
index cab604e..507ac00 100644
--- a/iw/lvm_dialog_gui.py
+++ b/iw/lvm_dialog_gui.py
@@ -565,42 +565,25 @@ class VolumeGroupEditor:
         dialog.show_all()
         # Here ends the gtk crap
 
-        while 1:
-            rc = dialog.run()
-            if rc == 2:
-                dialog.destroy()
-                return
-
-            actions = []
-            luksdev = None
-            targetSize = None
-            migrate = None
-            format = None
-            newluks = None
-
-            if templv.format.type == "luks":
-                format = self.luks[lv['name']]
-            else:
-                format = templv.format
-
-            if not templv.exists:
-                fmt_class = newfstypeCombo.get_active_value()
-            else:
-                # existing lv
-                fmt_class = self.fsoptionsDict["fstypeCombo"].get_active_value()
-
-            mountpoint = mountCombo.get_children()[0].get_text().strip()
-
+        # Here start the lv_check_functions
+        # Before we dare to create an lv device we check for stuff.  Gather all
+        # the checkfunctions in inner functions and put them in a list.  This
+        # decouples the check functions from the creating device stuff.  For
+        # all the checks True means pass and False means Fail.
+        def lv_check_validadte_name(*args, **kwargs):
             # validate logical volume name
-            lvname = lvnameentry.get_text().strip()
+            lvname = kwargs['lvname']
             if not templv.exists:
                 err = sanityCheckLogicalVolumeName(lvname)
                 if err:
                     self.intf.messageWindow(_("Illegal Logical Volume Name"),
                                             err, custom_icon="error")
-                    continue
+                    return False
+            return True
 
+        def lv_checks_name_in_use(*args, **kwargs):
             # check that the name is not already in use
+            lvname = kwargs['lvname']
             used = 0
             for _lv in self.lvs.values():
                 if _lv == lv:
@@ -611,16 +594,21 @@ class VolumeGroupEditor:
                     break
 
             if used:
-                self.intf.messageWindow(_("Illegal logical volume name"),
-                                        _("The logical volume name \"%s\" is "
-                                          "already in use. Please pick "
-                                          "another.") % (lvname,), custom_icon="error")
-                continue
+                self.intf.messageWindow(
+                        _("Illegal logical volume name"),
+                        _("The logical volume name \"%s\" is already in use. "
+                          "Please pick another.") % (lvname,),
+                        custom_icon="error")
+                return False
+            return True
 
+        def lv_check_mount_point(*args, **kwargs):
             # test mount point
             # check in pending logical volume requests
             # these may not have been put in master list of requests
             # yet if we have not hit 'OK' for the volume group creation
+            fmt_class = kwargs['fmt_class']
+            mountpoint = kwargs['mountpoint']
             if fmt_class().mountable and mountpoint:
                 used = 0
                 curmntpt = getattr(format, "mountpoint", None)
@@ -640,47 +628,109 @@ class VolumeGroupEditor:
                         break
 
                 if used:
-                    self.intf.messageWindow(_("Mount point in use"),
-                                            _("The mount point \"%s\" is in "
-                                              "use. Please pick another.") %
-                                            (mountpoint,),
-                                            custom_icon="error")
-                    continue
-
+                    self.intf.messageWindow(
+                            _("Mount point in use"),
+                            _("The mount point \"%s\" is in use. Please pick "
+                              "another.") % (mountpoint,),
+                            custom_icon="error")
+                    return False
+                return True
+
+        def lv_check_size_fomrat_value(*args, **kwargs):
             # check that size specification is numeric and positive
             if not templv.exists:
                 badsize = 0
                 try:
-                    size = long(sizeEntry.get_text())
+                    size = long(kwargs['size'])
                 except:
                     badsize = 1
 
                 if badsize or size <= 0:
-                    self.intf.messageWindow(_("Illegal size"),
-                                            _("The requested size as entered is "
-                                              "not a valid number greater "
-                                              "than 0."), custom_icon="error")
-                    continue
-            else:
-                size = templv.size
-
+                    self.intf.messageWindow(
+                            _("Illegal size"),
+                            _("The requested size as entered is not a valid number "
+                               "greater than 0."),
+                            custom_icon="error")
+                    return False
+            return True
+
+        def lv_check_size_limits(*args, **kwargs):
             # check that size specification is within limits
+            size = long(kwargs['size'])
             pesize = int(self.peCombo.get_active_value()) / 1024.0
             size = lvm.clampSize(size, pesize, roundup=True)
             maxlv = lvm.getMaxLVSize()
             if size > maxlv:
-                self.intf.messageWindow(_("Not enough space"),
-                                        _("The current requested size "
-                                          "(%10.2f MB) is larger than the maximum "
-                                          "logical volume size (%10.2f MB). "
-                                          "To increase this limit you can "
-                                          "create more Physical Volumes from "
-                                          "unpartitioned disk space and "
-                                          "add them to this Volume Group.")
-                                          %(size, maxlv),
-                                        custom_icon="error")
+                self.intf.messageWindow(
+                        _("Not enough space"),
+                        _("The current requested size (%10.2f MB) is larger "
+                          "than the maximum logical volume size (%10.2f MB). "
+                          "To increase this limit you can create more Physical "
+                          "Volumes from unpartitioned disk space and add them "
+                          "to this Volume Group.") %(size, maxlv),
+                        custom_icon="error")
+                return False
+            return True
+
+
+
+        # Note that the order in which these test are run matters. Specifically
+        # lv_check_size_fomrat_value needs to come before lv_check_size_limits.
+        lv_checks = [lv_check_validadte_name, lv_checks_name_in_use,
+                     lv_check_mount_point, lv_check_size_fomrat_value,
+                     lv_check_size_limits]
+        # Here end the lv_check_functions
+
+        while 1:
+            rc = dialog.run()
+            if rc == 2:
+                dialog.destroy()
+                return
+
+            actions = []
+            luksdev = None
+            targetSize = None
+            migrate = None
+            format = None
+            newluks = None
+
+            if templv.format.type == "luks":
+                format = self.luks[lv['name']]
+            else:
+                format = templv.format
+
+            if not templv.exists:
+                fmt_class = newfstypeCombo.get_active_value()
+            else:
+                # existing lv
+                fmt_class = self.fsoptionsDict["fstypeCombo"].get_active_value()
+
+            if not templv.exists:
+                size = sizeEntry.get_text() # We check for validity later.
+            else:
+                size = templv.size
+
+            mountpoint = mountCombo.get_children()[0].get_text().strip()
+            lvname = lvnameentry.get_text().strip()
+
+            # Call all the tests.
+            # If we find that something is wrong continue in the while loop.
+            # FIXME: handle the globals better.
+            kwargs = { "fmt_class" : fmt_class,
+                       "mountpoint" : mountpoint,
+                       "fomrmat" : format,
+                       "lvname" : lvname,
+                       "size" : size}
+            failed = False
+            for func in lv_checks:
+                if not func(*[], **kwargs):
+                    Falied = True
+            if failed:
                 continue
 
+            # FIXME: handle the globals better.
+            size = long(size)
+
             # Ok -- now we've done all the checks to validate the
             # user-specified parameters. Time to set up the device...
             origname = templv.lvname
-- 
1.6.0.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