From a83502aebed7c979256c50f10907c85456087dbe Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Fri, 22 Jun 2012 15:08:33 -0500
Subject: [PATCH 04/14] Put newly created devices in a page of their own.

Unset autopart flag after running ksdata.autopart.execute since we
are still techically doing custom partitioning.

Don't show devices queued for removal in the custom spoke.

Don't include Roots whose root device has been queued for removal.
---
 pyanaconda/ui/gui/spokes/custom.py |   60 +++++++++++++++++------------------
 1 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index a97b96e..96060c7 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -38,6 +38,7 @@ P_ = lambda x, y, z: gettext.ldngettext("anaconda", x, y, z)
 from pyanaconda.product import productName, productVersion
 from pyanaconda.storage.formats import device_formats
 from pyanaconda.storage.size import Size
+from pyanaconda.storage import Root
 
 from pyanaconda.ui.gui import UIObject
 from pyanaconda.ui.gui.spokes import NormalSpoke
@@ -50,6 +51,8 @@ from gi.repository import Gtk
 
 __all__ = ["CustomPartitioningSpoke"]
 
+new_install_name = = _("New %s %s Installation") % (productName, productVersion)
+
 class AddDialog(UIObject):
     builderObjects = ["addDialog"]
     mainWidgetName = "addDialog"
@@ -243,11 +246,15 @@ class CustomPartitioningSpoke(NormalSpoke):
         # We can only have one page expanded at a time.
         did_expand = False
 
+        unused = self._unusedDevices()
+        new_devices = [d for d in self.storage.devicetree.leaves if d not in unused and not d.exists]
+        roots = self.storage.roots[:]
+
         # If we've not yet run autopart, add an instance of CreateNewPage.  This
         # ensures it's only added once.
-        if not self._ran_autopart:
+        if not self._ran_autopart and not new_devices:
             page = CreateNewPage(self.on_create_clicked)
-            page.pageTitle = _("New %s %s Installation") % (productName, productVersion)
+            page.pageTitle = new_install_name
             self._accordion.addPage(page, cb=self.on_page_clicked)
             self._accordion.expandPage(page.pageTitle)
             did_expand = True
@@ -255,18 +262,32 @@ class CustomPartitioningSpoke(NormalSpoke):
             self._partitionsNotebook.set_current_page(0)
             label = self.builder.get_object("whenCreateLabel")
             label.set_text(self._when_create_text % (productName, productVersion))
+        elif new_devices:
+            swaps = [d for d in new_devices if d in self.storage.swaps]
+            mounts = dict([(d.format.mountpoint, d) for d in new_devices if getattr(d.format, "mountpoint", None)])
+            new_root = Root(mounts=mounts, swaps=swaps, name=new_install_name)
+            roots.insert(0, new_root)
 
         # Add in all the existing (or autopart-created) operating systems.
-        for root in self.storage.roots:
+        for root in roots:
+            if root.device and root.device not in self.storage.devices:
+                continue
+
             page = Page()
             page.pageTitle = root.name
 
-            for swap in root.swaps:
-                selector = page.addDevice("Swap", swap.size, None, self.on_selector_clicked)
-                selector._device = swap
+            for device in root.swaps:
+                if device not in self.storage.devices:
+                    continue
+
+                selector = page.addDevice("Swap", device.size, None, self.on_selector_clicked)
+                selector._device = device
                 selector._root = root
 
             for (mountpoint, device) in root.mounts.iteritems():
+                if device not in self.storage.devices:
+                    continue
+
                 selector = page.addDevice(self._mountpointName(mountpoint) or device.format.name, device.size, mountpoint, self.on_selector_clicked)
                 selector._device = device
                 selector._root = root
@@ -279,7 +300,6 @@ class CustomPartitioningSpoke(NormalSpoke):
                 self._accordion.expandPage(root.name)
 
         # Anything that doesn't go with an OS we understand?  Put it in the Other box.
-        unused = self._unusedDevices()
         if unused:
             page = UnknownPage()
             page.pageTitle = _("Unknown")
@@ -542,29 +562,7 @@ class CustomPartitioningSpoke(NormalSpoke):
         # FIXME:  Handle all the autopart exns here.
         self.data.autopart.autopart = True
         self.data.autopart.execute(self.storage, self.data, self.instclass)
-
-        # Create a new Root object for the new installation and put it into
-        # the storage object.  This means any boot-related devices we make for
-        # this new install (biosboot, etc.) will show up as unused and therefore
-        # be put into the Unknown page.
-        mounts = {}
-        swaps = []
-
-        # Devices just created by autopartitioning will be listed as unused
-        # since they are not yet a part of any known Root.
-        for device in self._unusedDevices():
-            if device.exists:
-                continue
-
-            if device.format.type == "swap":
-                swaps.append(device)
-
-            if getattr(device.format, "mountpoint", None):
-                mounts[device.format.mountpoint] = device
-
-        newName = _("New %s %s Installation") % (productName, productVersion)
-        root = Root(mounts=mounts, swaps=swaps, name=newName)
-        self.storage.roots.append(root)
+        self.data.autopart.autopart = False
 
         # Setting this ensures the CreateNewPage instance does not reappear when
         # refresh is called.
@@ -572,7 +570,7 @@ class CustomPartitioningSpoke(NormalSpoke):
 
         # And refresh the spoke to make the new partitions appear.
         self.refresh()
-        self._accordion.expandPage(newName)
+        self._accordion.expandPage(new_install_name)
 
     def on_device_type_changed(self, combo):
         text = combo.get_active_text()
-- 
1.7.7.6

