[PATCH 07/11] Add a mountpoint entry to the device options area.

David Lehman dlehman at redhat.com
Tue Sep 25 20:33:32 UTC 2012


This allows users to assign mountpoints to existing devices.
---
 pyanaconda/ui/gui/spokes/custom.glade |   80 ++++++++++++++++++++++++--------
 pyanaconda/ui/gui/spokes/custom.py    |   75 ++++++++++++++++++++++++++-----
 2 files changed, 123 insertions(+), 32 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.glade b/pyanaconda/ui/gui/spokes/custom.glade
index 8b1ae7e..a8c86ec 100644
--- a/pyanaconda/ui/gui/spokes/custom.glade
+++ b/pyanaconda/ui/gui/spokes/custom.glade
@@ -517,35 +517,52 @@ you'll be able to view their details here.</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkBox" id="box1">
+                              <object class="GtkGrid" id="grid5">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="spacing">6</property>
+			        <property name="row_spacing">6</property>
+			        <property name="column_spacing">6</property>
                                 <child>
-                                  <object class="GtkLabel" id="label4">
+                                  <object class="GtkLabel" id="mountPointLabel">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
-                                    <property name="label" translatable="yes">&lt;b&gt;Label:&lt;/b&gt;</property>
+                                    <property name="label" translatable="yes">&lt;b&gt;Mount Point:&lt;/b&gt;</property>
                                     <property name="use_markup">True</property>
                                   </object>
                                   <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">0</property>
+                                    <property name="left_attach">0</property>
+                                    <property name="top_attach">0</property>
+                                    <property name="width">1</property>
+                                    <property name="height">1</property>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkEntry" id="labelEntry">
+                                  <object class="GtkEntry" id="mountPointEntry">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="hexpand">True</property>
                                     <property name="invisible_char">●</property>
-                                    <property name="invisible_char_set">True</property>
+                                    <property name="completion">mountPointCompletion</property>
                                   </object>
                                   <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">1</property>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">0</property>
+                                    <property name="width">1</property>
+                                    <property name="height">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label4">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">&lt;b&gt;Label:&lt;/b&gt;</property>
+                                    <property name="use_markup">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">0</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="width">1</property>
+                                    <property name="height">1</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -557,9 +574,30 @@ you'll be able to view their details here.</property>
                                     <property name="use_markup">True</property>
                                   </object>
                                   <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">2</property>
+                                    <property name="left_attach">2</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="width">1</property>
+                                    <property name="height">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <object class="GtkEntry" id="labelEntry">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="hexpand">True</property>
+                                    <property name="invisible_char">●</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="width">1</property>
+                                    <property name="height">1</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -574,16 +612,17 @@ you'll be able to view their details here.</property>
                                     <property name="numeric">True</property>
                                   </object>
                                   <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">False</property>
-                                    <property name="position">3</property>
+                                    <property name="left_attach">3</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="width">1</property>
+                                    <property name="height">1</property>
                                   </packing>
                                 </child>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">True</property>
-                                <property name="position">2</property>
+                                <property name="position">4</property>
                               </packing>
                             </child>
                             <child>
@@ -653,6 +692,7 @@ you'll be able to view their details here.</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
                                         <property name="hexpand">True</property>
+                                        <signal name="changed" handler="on_fs_type_changed" swapped="no"/>
                                       </object>
                                       <packing>
                                         <property name="left_attach">1</property>
@@ -1159,7 +1199,7 @@ you'll be able to view their details here.</property>
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">True</property>
-                                <property name="position">3</property>
+                                <property name="position">5</property>
                               </packing>
                             </child>
                           </object>
diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 4087d9f..577b252 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -529,6 +529,13 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         unused = [d for d in self.unusedDevices if d.isleaf and d in self._devices]
         new_devices = [d for d in self._devices if not d.exists]
 
+        # if mountpoints have been assigned to any existing devices, go ahead
+        # and pull those in along with any existing swap devices
+        new_mounts = self.__storage.mountpoints.values()
+        if new_mounts:
+            new_devices.extend(self.__storage.mountpoints.values())
+            new_devices.extend(self.__storage.swaps)
+
         log.debug("ui: unused=%s" % [d.name for d in unused])
         log.debug("ui: new_devices=%s" % [d.name for d in new_devices])
 
@@ -709,11 +716,22 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         encrypted = self.builder.get_object("encryptCheckbox").get_active()
         log.debug("new encryption setting: %s" % encrypted)
 
-        # TODO: get mountpoint, disks
+        # TODO: get disks
         label = self.builder.get_object("labelEntry").get_text()
-
-        # FIXME: shouldn't we be getting this from the ui somehow instead?
-        mountpoint = getattr(device.format, "mountpoint", None)
+        old_label = getattr(device.format, "label", "") or ""
+
+        mountpoint = None   # None means format type is not mountable
+        mountPointEntry = self.builder.get_object("mountPointEntry")
+        if mountPointEntry.get_sensitive():
+            mountpoint = mountPointEntry.get_text()
+
+        old_mountpoint = getattr(device.format, "mountpoint", "") or ""
+        if mountpoint is not None and mountpoint != old_mountpoint:
+            error = validate_mountpoint(mountpoint, self.__storage.mountpoints.keys())
+            if error:
+                self._error = mountpoint_validation_msgs[error]
+                self.window.set_info(Gtk.MessageType.WARNING, self._error)
+                return
 
         raid_level = self._get_raid_level()
 
@@ -788,14 +806,12 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                         # btrfs subvol
                         raid_level = device.volume.dataLevel
 
-                    mountpoint = getattr(device.format, "mountpoint", None)
-                    label = getattr(device.format, "label", None)
-
                     try:
+                        # XXX FIXME: pass old raid level -- not new one
                         self._replace_device(device_type, device.size,
                                              fstype=device.format.type,
-                                             mountpoint=mountpoint,
-                                             label=label,
+                                             mountpoint=old_mountpoint,
+                                             label=old_label,
                                              raid_level=raid_level,
                                              selector=selector)
                     except StorageError as e:
@@ -806,6 +822,12 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                                              unrecoverable_error_msg)
                         self.window.show_all()
                         self._reset_storage()
+                else:
+                    # TODO: if old_mountpoint isn't set, remove this selector
+                    #       from the old root and add it to the new one
+                    selector.props.mountpoint = mountpoint
+                    selector.props.name = (self._mountpointName(mountpoint) or
+                                           selector._device.format.name)
 
             # update size props of all btrfs devices' selectors
             self._update_btrfs_selectors()
@@ -882,6 +904,14 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                                          _("Device reformat request failed. "
                                            "Click for details."))
                     self.window.show_all()
+                else:
+                    # TODO: if old_mountpoint isn't set, remove this selector
+                    #       from the old root and add it to the new one
+                    selector.props.mountpoint = mountpoint
+                    selector.props.name = (self._mountpointName(mountpoint) or
+                                           selector._device.format.name)
+
+            return
 
         # for encryption, I'm not sure if we'll want to modify the
         # container/device or just create a new one
@@ -890,12 +920,18 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         # Set various attributes that do not require actions.
         #
         #
-        if label and getattr(device.format, "label", label) != label:
+        if old_label != label and hasattr(device.format, "label") and \
+           not device.format.exists:
             device.format.label = label
 
-        if mountpoint and \
-           getattr(device.format, "mountpoint", mountpoint) != mountpoint:
+        if mountpoint and old_mountpoint != mountpoint:
             device.format.mountpoint = mountpoint
+            # TODO: if old_mountpoint isn't set, remove this selector
+            #       from the old root and add it to the new one
+            selector.props.mountpoint = mountpoint
+
+        selector.props.name = (self._mountpointName(mountpoint) or
+                               selector._device.format.name)
 
     def _get_raid_widget_dict(self, device_type):
         """ Return dict of widget tuples with feature keys for device_type. """
@@ -1036,6 +1072,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         log.debug("populate_right_side: %s" % selector._device)
         encryptCheckbox = self.builder.get_object("encryptCheckbox")
         labelEntry = self.builder.get_object("labelEntry")
+        mountPointEntry = self.builder.get_object("mountPointEntry")
         selectedDeviceLabel = self.builder.get_object("selectedDeviceLabel")
         selectedDeviceDescLabel = self.builder.get_object("selectedDeviceDescLabel")
         sizeSpinner = self.builder.get_object("sizeSpinner")
@@ -1047,7 +1084,12 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         selectedDeviceLabel.set_text(selector.props.name)
         selectedDeviceDescLabel.set_text(self._description(selector.props.name))
 
+        mountPointEntry.set_text(getattr(device.format, "mountpoint", "") or "")
+        mountPointEntry.set_sensitive(hasattr(device.format, "mountpoint"))
+
         labelEntry.set_text(getattr(device.format, "label", "") or "")
+        # We could label existing formats that have a labelFsProg if we added an
+        # ActionLabelFormat class.
         can_label = (hasattr(device.format, "label") and
                      not device.format.exists)
         labelEntry.set_sensitive(can_label)
@@ -1443,6 +1485,15 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         # And then display the first filesystem on the RHS.
         self._show_first_mountpoint()
 
+    def on_fs_type_changed(self, combo):
+        new_type = combo.get_active_text()
+        log.debug("fs type changed: %s" % new_type)
+        fmt = getFormat(new_type)
+        mountPointEntry = self.builder.get_object("mountPointEntry")
+        labelEntry = self.builder.get_object("labelEntry")
+        labelEntry.set_sensitive(hasattr(fmt, "label"))
+        mountPointEntry.set_sensitive(fmt.mountable)
+
     def on_device_type_changed(self, combo):
         new_type = combo.get_active()
         log.debug("device_type_changed: %s %s" % (new_type,
-- 
1.7.7.6



More information about the anaconda-patches mailing list