[PATCH 5/5] Update the API which controls where should spokes be displayed
Vratislav Podzimek
vpodzime at redhat.com
Wed Jan 2 10:22:34 UTC 2013
On Wed, 2012-12-19 at 16:09 +0100, Martin Sivak wrote:
> This patch adds two pieces to Spoke classes:
>
> should_run(environment_id, data)
> This method should return True if the spoke is to be displayed
> in the environment (currently only "anaconda" and "firstboot"
> are supported)
>
> @property configured()
> This property should return list of strings that will be
> stored to a config file, which will be passed to firstboot and
> GIE and will control whether spokes are to be displayed again
> or not.
> ---
> pyanaconda/ui/common.py | 56 ++++++++++++++++++++++++++++--------
> pyanaconda/ui/gui/hubs/__init__.py | 4 +++
> pyanaconda/ui/gui/spokes/password.py | 7 ++---
> pyanaconda/ui/tui/hubs/__init__.py | 4 +++
> 4 files changed, 54 insertions(+), 17 deletions(-)
>
> diff --git a/pyanaconda/ui/common.py b/pyanaconda/ui/common.py
> index 69d0390..f4e3d21 100644
> --- a/pyanaconda/ui/common.py
> +++ b/pyanaconda/ui/common.py
> @@ -116,25 +116,37 @@ class UIObject(object):
> return self._data
>
> class FirstbootSpokeMixIn(object):
> - """This MixIn class marks Spokes as usable for Firstboot."""
> -
> + """This MixIn class marks Spokes as usable for Firstboot
> + and Anaconda.
> + """
> @classmethod
> - def configure_tag(cls):
> - """This method defines textual id (or list of those) that will
> - be written into the after-install customization status
> - file for the firstboot and GIE to know that the spoke was
> - configured in anaconda."""
> - return None
> + def should_run(cls, environment, data):
> + """This method is responsible for beginning Spoke initialization
> + in the firstboot environment (even before __init__).
>
> + It should return True if the spoke is to be shown on the
> + FirstbootHub and False if it should be skipped.
I believe this sentence doesn't match the return statement at the end of
this method.
> +
> + It might be called multiple times, with or without (None)
> + the data argument.
> + """
> + return environment in ("anaconda", "firstboot")
> +
> +class FirstbootOnlySpokeMixIn(object):
> + """This MixIn class marks Spokes as usable for Firstboot."""
What about adding "ONLY" to the docstring ("...as usable ONLY for
Firstboot.")?
> @classmethod
> - def firstboot(cls):
> + def should_run(cls, environment, data):
> """This method is responsible for beginning Spoke initialization
> in the firstboot environment (even before __init__).
>
> It should return True if the spoke is to be shown on the
> - FirstbootHub and False if it should be skipped."""
> - return True
> -
> + FirstbootHub and False if it should be skipped.
> +
> + It might be called multiple times, with or without (None)
> + the data argument.
> + """
> + return environment in ("firstboot")
> +
> class Spoke(UIObject):
> """A Spoke is a single configuration screen. There are several different
> places where a Spoke can be displayed, each of which will have its own
> @@ -197,6 +209,18 @@ class Spoke(UIObject):
> self.instclass = instclass
> self.applyOnSkip = False
>
> + @classmethod
> + def should_run(cls, environment, data):
> + """This method is responsible for beginning Spoke initialization.
> +
> + It should return True if the spoke is to be shown while in
> + <environment> and False if it should be skipped.
> +
> + It might be called multiple times, with or without (None)
> + the data argument.
> + """
> + return environment in ("anaconda")
> +
> def apply(self):
> """Apply the selections made on this Spoke to the object's preset
> data object. This method must be provided by every subclass.
> @@ -204,6 +228,14 @@ class Spoke(UIObject):
> raise NotImplementedError
>
> @property
> + def configured(self):
> + """This method returns a list of textual ids that should
> + be written into the after-install customization status
> + file for the firstboot and GIE to know that the spoke was
> + configured and what value groups were provided."""
> + return ["%s.%s" % (self.__class__.__module__, self.__class__.__name__)]
> +
> + @property
> def completed(self):
> """Has this spoke been visited and completed? If not and the spoke is
> mandatory, a special warning icon will be shown on the Hub beside the
> diff --git a/pyanaconda/ui/gui/hubs/__init__.py b/pyanaconda/ui/gui/hubs/__init__.py
> index 3975b37..1f5141a 100644
> --- a/pyanaconda/ui/gui/hubs/__init__.py
> +++ b/pyanaconda/ui/gui/hubs/__init__.py
> @@ -147,6 +147,10 @@ class Hub(GUIObject, common.Hub):
>
> selectors = []
> for spokeClass in sorted(cats_and_spokes[c], key=lambda s: s.title):
> + # Check if this spoke is to be shown in anaconda
> + if not spokeClass.should_run("anaconda", self.data):
> + continue
> +
> # Create the new spoke and populate its UI with whatever data.
> # From here on, this Spoke will always exist.
> spoke = spokeClass(self.data, self.storage, self.payload, self.instclass)
> diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
> index 1bd424c..44be1ca 100644
> --- a/pyanaconda/ui/gui/spokes/password.py
> +++ b/pyanaconda/ui/gui/spokes/password.py
> @@ -31,12 +31,13 @@ import string
>
> from pyanaconda.ui.gui.spokes import NormalSpoke
> from pyanaconda.ui.gui.categories.user_settings import UserSettingsCategory
> +from pyanaconda.ui.common import FirstbootSpokeMixIn
> #from _isys import isCapsLockEnabled
>
> __all__ = ["PasswordSpoke"]
>
>
> -class PasswordSpoke(NormalSpoke):
> +class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke):
> builderObjects = ["passwordWindow"]
>
> mainWidgetName = "passwordWindow"
> @@ -47,10 +48,6 @@ class PasswordSpoke(NormalSpoke):
> icon = "dialog-password-symbolic"
> title = N_("ROOT PASSWORD")
>
> - @classmethod
> - def firstboot(cls):
> - return True
> -
Does this work? I mean is FirstbootSpokeMixIn's should_run called
instead of the Spoke's one? What does determine this? The ordering of
the superclasses? I believe it is worth a comment in the code.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list