[PATCH 3/4] Add the ability to select software in text UI.

Samantha N. Bueno sbueno+anaconda at redhat.com
Thu May 16 15:54:53 UTC 2013


---
 pyanaconda/ui/tui/spokes/software.py | 185 +++++++++++++++++++++++++++++++++++
 1 file changed, 185 insertions(+)
 create mode 100644 pyanaconda/ui/tui/spokes/software.py

diff --git a/pyanaconda/ui/tui/spokes/software.py b/pyanaconda/ui/tui/spokes/software.py
new file mode 100644
index 0000000..b80dd6f
--- /dev/null
+++ b/pyanaconda/ui/tui/spokes/software.py
@@ -0,0 +1,185 @@
+# Software selection text spoke
+#
+# Copyright (C) 2013  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Samantha N. Bueno <sbueno at redhat.com>
+#
+
+from pyanaconda.flags import flags
+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 MetadataError, DependencyError
+from pyanaconda.i18n import _
+
+
+__all__ = ["SoftwareSpoke"]
+
+
+class SoftwareSpoke(NormalTUISpoke):
+    """ Spoke used to read new value of text to represent source repo. """
+    title = _("Software selection")
+    category = "software"
+
+    def __init__(self, app, data, storage, payload, instclass):
+        NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
+        self._ready = False
+        self.errors = []
+        self._tx_id = None
+        # default to first selection (Gnome) in list of environments
+        self._selection = 0
+        self.environment = None
+
+        # for detecting later whether any changes have been made
+        self._origEnv = None
+
+    def initialize(self):
+        NormalTUISpoke.initialize(self)
+        threadMgr.add(AnacondaThread(name="AnaSoftwareWatcher", target=self._initialize))
+
+    def _initialize(self):
+        """ Private initialize. """
+        threadMgr.wait("AnaPayloadThread")
+        if flags.automatedInstall and self.data.packages.seen:
+            threadMgr.wait("AnaPayloadMDThread")
+        else:
+            try:
+                env = self.payload.environments
+            except MetadataError:
+                self.errors.append(_("No installation source available"))
+                return
+        self.payload.release()
+
+        self._ready = True
+
+    @property
+    def status(self):
+        """ something """
+        if self.errors:
+            return _("Error checking software selection")
+        if not self.ready:
+            return _("Processing...")
+        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:
+            self.environment = self.payload.environments[self._selection]
+
+        if not self.environment:
+            # Ks installs with %packages will have an env selected, unless
+            # they did an install without a desktop environment. This should
+            # catch that one case.
+            if flags.automatedInstall and self.data.packages.seen:
+                return _("Custom software selected")
+            return _("Nothing selected")
+
+        return self.payload.environmentDescription(self.environment)[0]
+
+    @property
+    def completed(self):
+        """ Always true. """
+        processingDone = not threadMgr.get("AnaCheckSoftwareThread") and \
+                         not self.errors and self.txid_valid
+
+        if flags.automatedInstall:
+            return processingDone and self.data.packages.seen
+        else:
+            return self.environment is not None and processingDone
+
+    def refresh(self, args=None):
+        """ Refresh screen. """
+        NormalTUISpoke.refresh(self, args)
+
+        environments = self.payload.environments
+
+        displayed = []
+        for env in environments:
+            displayed.append(CheckboxWidget(title="%s" % env, completed=(environments.index(env) == self._selection)))
+        print(_("Choose a desktop environment."))
+
+        def _prep(i, w):
+            """ Do some format magic for display. """
+            num = TextWidget("%2d)" % (i + 1))
+            return ColumnWidget([(4, [num]), (None, [w])], 1)
+
+        # split list of DE's into two columns
+        mid = len(environments) / 2
+        left = [_prep(i, w) for i, w in enumerate(displayed) if i <= mid]
+        right = [_prep(i, w) for i, w in enumerate(displayed) if i > mid]
+
+        cw = ColumnWidget([(38, left), (38, right)], 2)
+        self._window.append(cw)
+
+        return True
+
+    def input(self, args, key):
+        """ Handle the input; this chooses the desktop environment. """
+        if key.lower() == "c" and self._selection - 1 in range(len(self.payload.environments)):
+            self.apply()
+            return False
+
+        try:
+            keyid = int(key) - 1
+            if keyid in range(len(self.payload.environments)):
+                self._selection = keyid
+            return False
+        except (ValueError, IndexError):
+            return key
+
+    @property
+    def ready(self):
+        """ If we're ready to move on. """
+        return (not threadMgr.get("AnaSoftwareWatcher") and
+                not threadMgr.get("AnaPayloadMDThread") and
+                not threadMgr.get("AnaCheckSoftwareThread") and
+                self.payload.baseRepo is not None)
+
+    def apply(self):
+        """ Apply our selections """
+        self._apply()
+        self.data.packages.seen = True
+
+    def _apply(self):
+        """ Private apply. """
+        try:
+            self.environment = self.payload.environments[self._selection]
+            self.data.packages.seen = True
+        except IndexError:
+            return
+
+        self.payload.selectEnvironment(self.environment)
+        self._origEnv = self.environment
+        threadMgr.add(AnacondaThread(name="AnaCheckSoftwareThread",
+                                     target=self.checkSoftwareSelection))
+
+    def checkSoftwareSelection(self):
+        """ Depsolving """
+        try:
+            self.payload.checkSoftwareSelection()
+        except DependencyError:
+            self._tx_id = None
+        else:
+            self._tx_id = self.payload.txID
+
+    @property
+    def txid_valid(self):
+        """ Whether we have a valid yum tx id. """
+        return self._tx_id == self.payload.txID
-- 
1.7.11.7



More information about the anaconda-patches mailing list