[blivet:rhel7/master 5/5] on_device_type_changed() and populate_right_side() changes (#1076055)

mulhern amulhern at redhat.com
Thu Sep 25 18:03:36 UTC 2014


Related: rhbz#1076055

Changes are:

* Make device_type dependent on use_dev, not device.
* Remove line that sets sensitivity of _fsCombo in populate_right_side(),
it's done in on_device_type_changed()
* Fix the calculation of sensitivity for the size entry in
populate_right_side()
* Add _configButton sensitivity setting in populate_right_side()
* Make _nameEntry sensitivity unconditional and dependent on all the things
that seem to matter in on_device_type_changed().
* Add a comment explaining the peculiar situation _on_device_type_changed(),
for posterity.
* Given the information in the comment, only do things that save_right_side()
must also do if not called from save right side(). I don't know how events
are queued and handled, but I'm not sure that a method call that is
caused by an event that is triggered by an instruction in save_right_side()
will necessarily complete before subsequent instructions in save_right_side()
complete. It seems like a chancy thing to rely on, anyway.
* Move a chunk of code in on_device_type_changed() that only exists for
fsCombo related changes down with the rest of those changes.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 pyanaconda/ui/gui/spokes/custom.py | 74 +++++++++++++++++++++++---------------
 1 file changed, 46 insertions(+), 28 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 761d0d6..a08cb70 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -1906,8 +1906,10 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             self._device_container_encrypted = False
             self._device_container_size = SIZE_POLICY_AUTO
 
+        device_type = devicefactory.get_device_type(use_dev)
+
         self._device_container_raid_level = self._device_container_raid_level \
-           or defaultContainerRaidLevel(devicefactory.get_device_type(use_dev))
+           or defaultContainerRaidLevel(device_type)
 
         log.debug("updated device_container_name to %s", self._device_container_name)
         log.debug("updated device_container_raid_level to %s", self._device_container_raid_level)
@@ -2057,7 +2059,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             elif itr[0] == _(DEVICE_TEXT_LVM_THINP):
                 thinp_pos = idx
 
-        device_type = devicefactory.get_device_type(device)
         type_index_map = {DEVICE_TYPE_PARTITION: partition_pos,
                           DEVICE_TYPE_BTRFS: btrfs_pos,
                           DEVICE_TYPE_LVM: lvm_pos,
@@ -2082,8 +2083,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             self._device_name_dict[_type] = name
 
         self._typeCombo.set_active(type_index_map[device_type])
-        fancy_set_sensitive(self._fsCombo, self._reformatCheckbox.get_active() and
-                                           device_type != DEVICE_TYPE_BTRFS)
 
         # you can't change the type of an existing device
         fancy_set_sensitive(self._typeCombo, not use_dev.exists)
@@ -2099,11 +2098,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         if device_type in [DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM_THINP]:
             fancy_set_sensitive(self._encryptCheckbox, False)
 
-        # The size entry is only sensitive for resizable existing devices and
-        # new devices that are not btrfs subvolumes.
-        # Do this after the device type combo is set since
-        # on_device_type_changed doesn't account for device existence.
-        fancy_set_sensitive(self._sizeEntry, device.resizable or (not device.exists and device.format.type != "btrfs"))
+        raw_device_resizable = use_dev.resizable or (not use_dev.exists and device_type != DEVICE_TYPE_BTRFS)
+        fancy_set_sensitive(self._sizeEntry, raw_device_resizable and (use_dev == use_dev.raw_device or not device.exists))
 
         if self._sizeEntry.get_sensitive():
             self._sizeEntry.props.has_tooltip = False
@@ -2114,9 +2110,9 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
 
         self._populate_raid(get_raid_level(device))
         self._populate_container(device=use_dev)
-        # do this last in case this was set sensitive in on_device_type_changed
-        if use_dev.exists or use_dev.type == "btrfs volume":
-            fancy_set_sensitive(self._nameEntry, False)
+        self._configButton.set_sensitive(not use_dev.exists and device_type not in (DEVICE_TYPE_LVM, DEVICE_TYPE_LVM_THINP, DEVICE_TYPE_BTRFS))
+
+        fancy_set_sensitive(self._nameEntry, not use_dev.exists and use_dev.type != "btrfs volume" and device_type in (DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM, DEVICE_TYPE_LVM_THINP))
 
     ###
     ### SIGNAL HANDLERS
@@ -3033,6 +3029,19 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             map(really_hide, [container_label, self._containerCombo, self._modifyContainerButton])
 
     def on_device_type_changed(self, combo):
+        """ This method is called when the user changes the device type
+            and also in populate_right_side(), when the active device type
+            is chosen.
+
+            If it is called due to a user change, the raw device does not
+            exist and a selector is available. Otherwise, nothing is
+            known about the device and the selector is unavailable.
+
+            This means that a good deal of this method must be repeated in
+            populate_right_side(), where information about the device is
+            available.
+        """
+
         if not self._initialized:
             return
 
@@ -3041,6 +3050,31 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         if new_type is None:
             return
 
+        selector = self._current_selector
+        device = selector._device if selector else None
+
+        # Only do the following if this method is called due to a user
+        # action, and device is available. If device is not available, it
+        # will be redone in save_right_side, anyway.
+        if device:
+            use_dev = device.raw_device
+
+            self._configButton.set_sensitive(new_type not in (DEVICE_TYPE_LVM, DEVICE_TYPE_LVM_THINP, DEVICE_TYPE_BTRFS))
+
+            # Refilter the RAID store before repopulating it, so RAID levels
+            # are available.
+            self._raidStoreFilter.refilter()
+
+            self._populate_raid(defaultRaidLevel(new_type))
+            self._populate_container()
+
+            fancy_set_sensitive(self._nameEntry, use_dev != "btrfs volume" and new_type in (DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM, DEVICE_TYPE_MD, DEVICE_TYPE_LVM_THINP))
+            self._nameEntry.set_text(self._device_name_dict[new_type])
+
+            raw_device_resizable = new_type != DEVICE_TYPE_BTRFS
+            device_resizable = raw_device_resizable and (use_dev == device or not device.exists)
+            fancy_set_sensitive(self._sizeEntry, device_resizable)
+
         # if device type is not btrfs we want to make sure btrfs is not in the
         # fstype combo
         include_btrfs = False
@@ -3052,22 +3086,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             include_btrfs = test_fmt.supported and test_fmt.formattable
             fs_type_sensitive = False
 
-        # lvm uses the RHS to set disk set. no foolish minds here.
-        exists = self._current_selector and self._current_selector._device.exists
-        self._configButton.set_sensitive(not exists and new_type not in (DEVICE_TYPE_LVM, DEVICE_TYPE_LVM_THINP, DEVICE_TYPE_BTRFS))
-
-        # this has to be done before calling populate_raid since it will need
-        # the raid level combo to contain the relevant raid levels for the new
-        # device type
-        self._raidStoreFilter.refilter()
-
-        self._populate_raid(defaultRaidLevel(new_type))
-        self._populate_container()
-
-        fancy_set_sensitive(self._nameEntry, new_type in (DEVICE_TYPE_BTRFS, DEVICE_TYPE_LVM, DEVICE_TYPE_MD, DEVICE_TYPE_LVM_THINP))
-        self._nameEntry.set_text(self._device_name_dict[new_type])
-        fancy_set_sensitive(self._sizeEntry, new_type != DEVICE_TYPE_BTRFS)
-
         # begin btrfs magic
         model = self._fsCombo.get_model()
         btrfs_included = False
-- 
1.9.3



More information about the anaconda-patches mailing list