[master/rhel7-branch] Re-apply disk selection on error in TUi storage. (#1056316)

Samantha N. Bueno sbueno+anaconda at redhat.com
Wed Feb 19 15:48:18 UTC 2014


(This includes bcl's suggestion to reduce duplication of functions/logic.)

====

This copies over some more logic from the GUI storage spoke
that should make error handling a bit more sane.

Resolves: rhbz#1056316
---
 pyanaconda/ui/gui/spokes/storage.py | 19 +++++--------------
 pyanaconda/ui/lib/disks.py          |  9 +++++++++
 pyanaconda/ui/tui/spokes/storage.py |  4 +++-
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index bdd48ef..9c73140 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -43,7 +43,7 @@
 from gi.repository import Gdk, GLib, Gtk, AnacondaWidgets
 
 from pyanaconda.ui.communication import hubQ
-from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, size_str
+from pyanaconda.ui.lib.disks import getDisks, isLocalDisk, size_str, applyDiskSelection
 from pyanaconda.ui.gui import GUIObject
 from pyanaconda.ui.gui.spokes import NormalSpoke
 from pyanaconda.ui.gui.spokes.lib.cart import SelectedDisksDialog
@@ -304,17 +304,8 @@ class StorageSpoke(NormalSpoke, StorageChecker):
         self._encrypted = self.builder.get_object("encryptionCheckbox")
         self._reclaim = self.builder.get_object("reclaimCheckbox")
 
-    def _applyDiskSelection(self, use_names):
-        onlyuse = use_names[:]
-        for disk in (d for d in self.storage.disks if d.name in onlyuse):
-            onlyuse.extend(d.name for d in disk.ancestors
-                           if d.name not in onlyuse)
-
-        self.data.ignoredisk.onlyuse = onlyuse
-        self.data.clearpart.drives = use_names[:]
-
     def apply(self):
-        self._applyDiskSelection(self.selected_disks)
+        applyDiskSelection(self.selected_disks)
         self.data.autopart.autopart = self.autopart
         self.data.autopart.type = self.autoPartType
         self.data.autopart.encrypted = self.encrypted
@@ -371,7 +362,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
             self.storage.reset()
             self.disks = getDisks(self.storage.devicetree)
             # now set ksdata back to the user's specified config
-            self._applyDiskSelection(self.selected_disks)
+            applyDiskSelection(self.selected_disks)
         except BootLoaderError as e:
             log.error("BootLoader setup failed: %s", e)
             StorageChecker.errors = str(e).split("\n")
@@ -632,7 +623,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
 
         # if there's only one disk, select it by default
         if len(self.disks) == 1 and not self.selected_disks:
-            self._applyDiskSelection([self.disks[0].name])
+            applyDiskSelection([self.disks[0].name])
 
         self._ready = True
         hubQ.send_ready(self.__class__.__name__, False)
@@ -899,7 +890,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
 
         # However, we do want to apply current selections so the disk cart off
         # the filter spoke will display the correct information.
-        self._applyDiskSelection(self.selected_disks)
+        applyDiskSelection(self.selected_disks)
 
         self.skipTo = "FilterSpoke"
         NormalSpoke.on_back_clicked(self, button)
diff --git a/pyanaconda/ui/lib/disks.py b/pyanaconda/ui/lib/disks.py
index 486208b..ddfc6ea 100644
--- a/pyanaconda/ui/lib/disks.py
+++ b/pyanaconda/ui/lib/disks.py
@@ -82,3 +82,12 @@ def size_str(mb):
         spec = "%f mb" % mb
 
     return str(Size(spec=spec)).upper()
+
+def applyDiskSelection(use_names):
+    onlyuse = use_names[:]
+    for disk in (d for d in self.storage.disks if d.name in onlyuse):
+        onlyuse.extend(d.name for d in disk.ancestors
+                       if d.name not in onlyuse)
+
+    self.data.ignoredisk.onlyuse = onlyuse
+    self.data.clearpart.drives = use_names[:]
diff --git a/pyanaconda/ui/tui/spokes/storage.py b/pyanaconda/ui/tui/spokes/storage.py
index b4d40f1..4dc458d 100644
--- a/pyanaconda/ui/tui/spokes/storage.py
+++ b/pyanaconda/ui/tui/spokes/storage.py
@@ -22,7 +22,7 @@
 # which has the same license and authored by David Lehman <dlehman at redhat.com>
 #
 
-from pyanaconda.ui.lib.disks import getDisks, size_str
+from pyanaconda.ui.lib.disks import getDisks, size_str, applyDiskSelection
 from pyanaconda.ui.tui.spokes import NormalTUISpoke
 from pyanaconda.ui.tui.simpleline import TextWidget, CheckboxWidget
 
@@ -297,6 +297,8 @@ class StorageSpoke(NormalTUISpoke):
             self.storage.config.update(self.data)
             self.storage.autoPartType = self.data.clearpart.type
             self.storage.reset()
+            # now set ksdata back to the user's specified config
+            applyDiskSelection(self.selected_disks)
             self._ready = True
         except BootLoaderError as e:
             log.error("BootLoader setup failed: %s", e)
-- 
1.8.3.1



More information about the anaconda-patches mailing list