[PATCH 3/4] Fix the FIXME re: tui default software selection
David Shea
dshea at redhat.com
Fri Jan 9 19:00:27 UTC 2015
Handle selecting the default environment in the TUI the same way it's
done in the GUI: launch a thread from initialize that waits for
THREAD_PAYLOAD, sets the default, and starts a dependency check.
Also connect to payloadMgr events to reset the selection on source
changes and for more error detection.
---
pyanaconda/ui/tui/spokes/software.py | 97 +++++++++++++++++++++++++-----------
1 file changed, 67 insertions(+), 30 deletions(-)
diff --git a/pyanaconda/ui/tui/spokes/software.py b/pyanaconda/ui/tui/spokes/software.py
index f1a66bf..03f5347 100644
--- a/pyanaconda/ui/tui/spokes/software.py
+++ b/pyanaconda/ui/tui/spokes/software.py
@@ -24,11 +24,12 @@ from pyanaconda.ui.categories.software import SoftwareCategory
from pyanaconda.ui.tui.spokes import NormalTUISpoke
from pyanaconda.ui.tui.simpleline import TextWidget, ColumnWidget, CheckboxWidget
from pyanaconda.threads import threadMgr, AnacondaThread
-from pyanaconda.packaging import DependencyError, PackagePayload
+from pyanaconda.packaging import DependencyError, PackagePayload, payloadMgr
from pyanaconda.i18n import N_, _, C_
from pyanaconda.constants import THREAD_PAYLOAD
from pyanaconda.constants import THREAD_CHECK_SOFTWARE
+from pyanaconda.constants import THREAD_SOFTWARE_WATCHER
from pyanaconda.constants_text import INPUT_PROCESSED
__all__ = ["SoftwareSpoke"]
@@ -43,8 +44,7 @@ class SoftwareSpoke(NormalTUISpoke):
NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
self.errors = []
self._tx_id = None
- # default to first selection (Gnome) in list of environments
- self._selection = 0
+ self._selection = None
self.environment = None
# for detecting later whether any changes have been made
@@ -53,6 +53,41 @@ class SoftwareSpoke(NormalTUISpoke):
# are we taking values (package list) from a kickstart file?
self._kickstarted = flags.automatedInstall and self.data.packages.seen
+ # Register event listeners to update our status on payload events
+ payloadMgr.addListener(payloadMgr.STATE_START, self._payload_start)
+ payloadMgr.addListener(payloadMgr.STATE_FINISHED, self._payload_finished)
+ payloadMgr.addListener(payloadMgr.STATE_ERROR, self._payload_error)
+
+ def initialize(self):
+ # Start a thread to wait for the payload and run the first, automatic
+ # dependency check
+ super(SoftwareSpoke, self).initialize()
+ threadMgr.add(AnacondaThread(name=THREAD_SOFTWARE_WATCHER,
+ target=self._initialize))
+
+ def _initialize(self):
+ threadMgr.wait(THREAD_PAYLOAD)
+
+ if not self._kickstarted:
+ # Select the first environment by default
+ if self.payload.environments:
+ self._selection = 0
+
+ # Apply the initial selection
+ self._apply()
+
+ def _payload_start(self):
+ # Source is changing, invalidate the software selection and clear the
+ # errors
+ self._selection = None
+ self.errors = []
+
+ def _payload_finished(self):
+ self.environment = self.data.packages.environment
+
+ def _payload_error(self):
+ self.errors = [payloadMgr.error]
+
@property
def showable(self):
return isinstance(self.payload, PackagePayload)
@@ -69,14 +104,6 @@ class SoftwareSpoke(NormalTUISpoke):
if not self.txid_valid:
return _("Source changed - please verify")
- ## FIXME:
- # quite ugly, but env isn't getting set to gnome (or anything) by
- # default, and it really should be so we can maintain consistency
- # with graphical behavior
- if self._selection >= 0 and not self.environment \
- and not flags.automatedInstall:
- self.apply()
-
if not self.environment:
# Ks installs with %packages will have an env selected, unless
# they did an install without a desktop environment. This should
@@ -167,7 +194,8 @@ class SoftwareSpoke(NormalTUISpoke):
def ready(self):
""" If we're ready to move on. """
return (not threadMgr.get(THREAD_PAYLOAD) and
- not threadMgr.get(THREAD_CHECK_SOFTWARE))
+ not threadMgr.get(THREAD_CHECK_SOFTWARE) and
+ not threadMgr.get(THREAD_SOFTWARE_WATCHER))
def apply(self):
""" Apply our selections """
@@ -177,34 +205,43 @@ class SoftwareSpoke(NormalTUISpoke):
self._kickstarted = False
self.data.packages.seen = True
- threadMgr.add(AnacondaThread(name=THREAD_CHECK_SOFTWARE,
- target=self.checkSoftwareSelection))
-
def _apply(self):
""" Private apply. """
- self.environment = self.payload.environments[self._selection]
- if not self.environment:
- return
-
- if not self._origEnv:
- # nothing selected before, select the environment
- self.payload.selectEnvironment(self.environment)
- elif self._origEnv != self.environment:
- # environment changed, clear the list of packages and select the new
- # one
- self.payload.data.packages.groupList = []
- self.payload.selectEnvironment(self.environment)
+ if 0 <= self._selection < len(self.payload.environments):
+ self.environment = self.payload.environments[self._selection]
else:
- # no change
+ self.environment = None
return
- self._origEnv = self.environment
+ changed = False
+
+ # Not a kickstart with packages, setup the selected environment
+ if not self._kickstarted:
+ if not self._origEnv:
+ # nothing selected before, select the environment
+ self.payload.selectEnvironment(self.environment)
+ changed = True
+ elif self._origEnv != self.environment:
+ # environment changed, clear the list of packages and select the new
+ # one
+ self.payload.data.packages.groupList = []
+ self.payload.selectEnvironment(self.environment)
+ changed = True
+
+ self._origEnv = self.environment
+
+ # Check the software selection
+ if changed:
+ threadMgr.add(AnacondaThread(name=THREAD_CHECK_SOFTWARE,
+ target=self.checkSoftwareSelection))
+
def checkSoftwareSelection(self):
""" Depsolving """
try:
self.payload.checkSoftwareSelection()
- except DependencyError:
+ except DependencyError as e:
+ self.errors = [e.message]
self._tx_id = None
else:
self._tx_id = self.payload.txID
--
2.1.0
More information about the anaconda-patches
mailing list