[master/rhel7 v2] Change the reclaim space button rules (#980496)

Vratislav Podzimek vpodzime at redhat.com
Wed Jan 29 06:50:38 UTC 2014


On Tue, 2014-01-28 at 11:48 -0800, Brian C. Lane wrote:
> Now that the reclaim dialog can be entered with pre-existing free space
> the button state needs to be updated with the initial amount of free
> space. And its sensitivity should depend on whether or not there is
> enough free space, not on delete actions, which may be 0 if you are only
> shrinking a partition.
> 
> Change _recursiveRemove to check for protected children and only delete
> the unprotected ones. If there are none, delete the whole device.
> 
> Related: rhbz#980496
> ---
>  pyanaconda/ui/gui/spokes/lib/resize.py | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/pyanaconda/ui/gui/spokes/lib/resize.py b/pyanaconda/ui/gui/spokes/lib/resize.py
> index b398eda..c1dfcd3 100644
> --- a/pyanaconda/ui/gui/spokes/lib/resize.py
> +++ b/pyanaconda/ui/gui/spokes/lib/resize.py
> @@ -218,6 +218,7 @@ class ResizeDialog(GUIObject):
>                               "installation below.")
>  
>          self._reclaimDescLabel.set_text(description)
> +        self._update_reclaim_button(Size(0))
>  
>      def _update_labels(self, nDisks=None, totalReclaimable=None, selectedReclaimable=None):
>          if nDisks is not None and totalReclaimable is not None:
> @@ -291,13 +292,7 @@ class ResizeDialog(GUIObject):
>              self._deleteButton.set_sensitive(False)
>  
>      def _update_reclaim_button(self, got):
> -        # The reclaim button is sensitive if two conditions are met:
> -        # (1) There's enough available space (existing free/unpartitioned space,
> -        #     shrink space, etc.) on all disks.
> -        # (2) At least one destructive action has been chosen.
> -        nDeletes = len([row for row in self._diskStore if row[ACTION_COL] == _(DELETE)])
> -        need = self.payload.spaceRequired
> -        self._resizeButton.set_sensitive(got+self._initialFreeSpace >= need and nDeletes > 0)
> +        self._resizeButton.set_sensitive(got+self._initialFreeSpace >= self.payload.spaceRequired)
>  
>      def refresh(self, disks):
>          super(ResizeDialog, self).refresh()
> @@ -395,9 +390,20 @@ class ResizeDialog(GUIObject):
>          self._update_action_buttons(selectedRow)
>  
>      def _recursiveRemove(self, device):
> -        children = [d for d in self.storage.devices if device in d.parents and not d.protected]
> -        for child in children:
> -            self.storage.recursiveRemove(child)
> +        """ Remove a device, or if it has protected children, just remove the
> +            unprotected children.
> +        """
> +        if not any(d for d in self.storage.devices \
> +                   if device in d.parents and d.protected):
> +            # No protected children, remove the device
> +            self.storage.recursiveRemove(device)
> +        else:
> +            # Only remove unprotected children
> +            unprotected = (d for d in self.storage.devices \
> +                           if device in d.parents and not d.protected)
> +            for child in unprotected:
> +                if child in self.storage.devices:
> +                    self.storage.recursiveRemove(child)
>  
>      def _scheduleActions(self, model, path, itr, *args):
>          obj = PartStoreRow(*model[itr])
Generators of the Python, unite! Neat code! :)

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list