[PATCH 1/5] Validate mountpoints in the add-a-mountpoint dialog.

David Lehman dlehman at redhat.com
Thu Sep 6 22:02:54 UTC 2012


---
 pyanaconda/ui/gui/spokes/custom.glade |    4 +-
 pyanaconda/ui/gui/spokes/custom.py    |   40 +++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.glade b/pyanaconda/ui/gui/spokes/custom.glade
index 1a0bf8d..e16ffa6 100644
--- a/pyanaconda/ui/gui/spokes/custom.glade
+++ b/pyanaconda/ui/gui/spokes/custom.glade
@@ -144,6 +144,7 @@ after creating the mount point below.</property>
                 <property name="can_focus">True</property>
                 <property name="invisible_char">●</property>
                 <property name="completion">mountPointCompletion</property>
+                <signal name="changed" handler="on_text_changed" swapped="no"/>
               </object>
               <packing>
                 <property name="left_attach">1</property>
@@ -155,7 +156,6 @@ after creating the mount point below.</property>
             <child>
               <object class="GtkBox" id="addLabelWarningBox">
                 <property name="can_focus">False</property>
-                <property name="no_show_all">True</property>
                 <property name="valign">start</property>
                 <property name="spacing">6</property>
                 <child>
@@ -172,7 +172,7 @@ after creating the mount point below.</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="label13">
+                  <object class="GtkLabel" id="mountPointWarningLabel">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="label" translatable="yes">That mount point is already in
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 5de6c35..117586b 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -17,6 +17,7 @@
 # Red Hat, Inc.
 #
 # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
+#                    David Lehman <dlehman at redhat.com>
 #
 
 # TODO:
@@ -115,6 +116,11 @@ class AddDialog(GUIObject):
     mainWidgetName = "addDialog"
     uiFile = "spokes/custom.glade"
 
+    invalid_mountpoint_msg = _("That mount point is invalid. "
+                               "Try something else?")
+    mountpoint_in_use_msg = _("That mount point is already in use. "
+                              "Try something else?")
+
     def __init__(self, *args, **kwargs):
         self.mountpoints = kwargs.pop("mountpoints", [])
         GUIObject.__init__(self, *args, **kwargs)
@@ -132,9 +138,33 @@ class AddDialog(GUIObject):
         completion.set_text_column(0)
         completion.set_popup_completion(True)
 
+    def on_text_changed(self, entry):
+        mountpoint = self.builder.get_object("addMountPointEntry").get_text()
+        warning_label = self.builder.get_object("mountPointWarningLabel")
+        if mountpoint in self.mountpoints:
+            warning_label.set_text(self.mountpoint_in_use_msg)
+            self._warningBox.show_all()
+            sensitive = False
+        elif not mountpoint:
+            self._warningBox.hide()
+            sensitive = False
+        elif (mountpoint.lower() not in ("swap", "biosboot", "prepboot") and
+              ((len(mountpoint) > 1 and mountpoint.endswith("/")) or
+               not mountpoint.startswith("/") or
+               " " in mountpoint or
+               re.search(r'/\.*/', mountpoint) or
+               re.search(r'/\.+$', mountpoint))):
+            warning_label.set_text(self.invalid_mountpoint_msg)
+            self._warningBox.show_all()
+            sensitive = False
+        else:
+            self._warningBox.hide()
+            sensitive = True
+
+        self.builder.get_object("addConfirmButton").set_sensitive(sensitive)
+
     def on_add_confirm_clicked(self, button, *args):
         self.mountpoint = self.builder.get_object("addMountPointEntry").get_text()
-
         size_text = self.builder.get_object("sizeEntry").get_text().strip()
 
         # if no unit was specified, default to MB
@@ -150,6 +180,8 @@ class AddDialog(GUIObject):
 
     def refresh(self):
         GUIObject.refresh(self)
+        self._warningBox = self.builder.get_object("addLabelWarningBox")
+        self._warningBox.hide()
 
     def run(self):
         return self.window.run()
@@ -963,12 +995,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         if mountpoint.lower() == "swap":
             mountpoint = None
 
-        # TODO: validate the mountpoint for sanity
-        if mountpoint in self.__storage.mountpoints:
-            # FIXME: do this in the add dialog
-            log.error("ignoring request to create duplicate %s" % mountpoint)
-            return
-
         device_type = self.data.autopart.type
         if device_type == AUTOPART_TYPE_LVM and \
              mountpoint == "/boot/efi":
-- 
1.7.7.6



More information about the anaconda-patches mailing list