[PATCH 2/3] Add TUI Eula spoke (#1000409)

Vratislav Podzimek vpodzime at redhat.com
Mon Oct 7 15:16:46 UTC 2013


Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 initial_setup/tui/hubs/initial_setup_hub.py |  2 +-
 initial_setup/tui/spokes/eula.py            | 87 +++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 initial_setup/tui/spokes/eula.py

diff --git a/initial_setup/tui/hubs/initial_setup_hub.py b/initial_setup/tui/hubs/initial_setup_hub.py
index 73f8269..bd214a6 100644
--- a/initial_setup/tui/hubs/initial_setup_hub.py
+++ b/initial_setup/tui/hubs/initial_setup_hub.py
@@ -13,7 +13,7 @@ _ = lambda x: gettext.ldgettext("initial-setup", x)
 N_ = lambda x: x
 
 class InitialSetupMainHub(TUIHub):
-    categories = ["password", "localization"]
+    categories = ["password", "localization", "system"]
 
     prod_title = product.product_title()
     if prod_title:
diff --git a/initial_setup/tui/spokes/eula.py b/initial_setup/tui/spokes/eula.py
new file mode 100644
index 0000000..56ee3fa
--- /dev/null
+++ b/initial_setup/tui/spokes/eula.py
@@ -0,0 +1,87 @@
+"""EULA TUI spoke for the Initial Setup"""
+
+import gettext
+
+from pyanaconda.ui.tui.spokes import NormalTUISpoke
+from pyanaconda.ui.tui.simpleline.widgets import TextWidget, CheckboxWidget
+from pyanaconda.ui.tui.simpleline.base import UIScreen
+from pyanaconda.ui.common import FirstbootOnlySpokeMixIn
+from pyanaconda.constants_text import INPUT_PROCESSED
+from initial_setup.product import get_license_file_name
+
+_ = lambda x: gettext.ldgettext("initial-setup", x)
+N_ = lambda x: x
+
+__all__ = ["EULAspoke"]
+
+class EULAspoke(FirstbootOnlySpokeMixIn, NormalTUISpoke):
+    title = _("License information")
+    category = "system"
+
+    def __init__(self, *args, **kwargs):
+        NormalTUISpoke.__init__(self, *args, **kwargs)
+
+        self._have_eula = True
+
+    def initialize(self):
+        NormalTUISpoke.initialize(self)
+
+        license_file = get_license_file_name()
+        if not license_file:
+            self._have_eula = False
+
+    def refresh(self, args=None):
+        NormalTUISpoke.refresh(self, args)
+
+        if self._have_eula:
+            self._window += [TextWidget("    1) %s" % _("Read the License Agreement")), ""]
+            self._window += [CheckboxWidget(title="2) %s" % _("I accept the license agreement."),
+                                            completed=self.data.eula.agreed), ""]
+        else:
+            self._window += [TextWidget(_("No license found. Please report this "
+                                          "at http://bugzilla.redhat.com")), ""]
+
+    @property
+    def completed(self):
+        return not self._have_eula or self.data.eula.agreed
+
+    @property
+    def status(self):
+        if not self._have_eula:
+            return _("No license found")
+
+        return _("License agreed") if self.data.eula.agreed else _("License not agreed")
+
+    def input(self, args, key):
+        try:
+            keyid = int(key)
+        except ValueError:
+            # only number choices are processed here
+            return key
+
+        if keyid == 1:
+            eula_screen = LicenseScreen(self._app)
+            self.app.switch_screen_with_return(eula_screen)
+            return INPUT_PROCESSED
+        elif keyid == 2:
+            self.data.eula.agreed = not self.data.eula.agreed
+            return INPUT_PROCESSED
+
+        return key
+
+class LicenseScreen(UIScreen):
+    # no title needed, we just want to show the license
+    title = ""
+
+    def __init__(self, app, screen_height=25):
+        UIScreen.__init__(self, app, screen_height)
+        license_file = get_license_file_name()
+        with open(license_file, "r") as fobj:
+            self._buf = u"".join(fobj.xreadlines())
+
+    def refresh(self, args=None):
+        self._window += [TextWidget(self._buf), ""]
+
+    def prompt(self, args=None):
+        self.close()
+        return None
-- 
1.7.11.7



More information about the anaconda-patches mailing list