[PATCH] Split __init__ and setup in TUI screens so we can set the environment and search paths
Vratislav Podzimek
vpodzime at redhat.com
Fri Jan 18 08:51:11 UTC 2013
On Thu, 2013-01-17 at 14:14 +0100, Martin Sivak wrote:
> ---
> pyanaconda/ui/tui/__init__.py | 10 +++++++---
> pyanaconda/ui/tui/hubs/__init__.py | 7 ++++---
> pyanaconda/ui/tui/simpleline/base.py | 8 ++++++++
> 3 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/pyanaconda/ui/tui/__init__.py b/pyanaconda/ui/tui/__init__.py
> index ba6d5b8..c8212b6 100644
> --- a/pyanaconda/ui/tui/__init__.py
> +++ b/pyanaconda/ui/tui/__init__.py
> @@ -112,6 +112,8 @@ class YesNoDialog(tui.UIScreen):
> class TextUserInterface(ui.UserInterface):
> """This is the main class for Text user interface."""
>
> + ENVIRONMENT = "anaconda"
> +
> def __init__(self, storage, payload, instclass):
> """
> For detailed description of the arguments see
> @@ -145,7 +147,7 @@ class TextUserInterface(ui.UserInterface):
> os.path.join(path, "hubs"))
> for path in pathlist]
> }
> -
> +
> def _list_hubs(self):
> """returns the list of hubs to use"""
> return [SummaryHub, ProgressHub]
> @@ -153,7 +155,7 @@ class TextUserInterface(ui.UserInterface):
> def _is_standalone(self, spoke):
> """checks if the passed spoke is standalone"""
> return isinstance(spoke, StandaloneSpoke)
> -
> +
> def setup(self, data):
> """Construct all the objects required to implement this interface.
> This method must be provided by all subclasses.
> @@ -165,7 +167,7 @@ class TextUserInterface(ui.UserInterface):
> path = os.path.join(os.path.dirname(__file__), "spokes")
> spokes = self._collectActionClasses(self.paths["spokes"], StandaloneSpoke)
> actionClasses = self._orderActionClasses(spokes, _hubs)
> -
> +
> for klass in actionClasses:
> obj = klass(self._app, data, self.storage, self.payload, self.instclass)
>
> @@ -179,6 +181,8 @@ class TextUserInterface(ui.UserInterface):
> if hasattr(obj, "set_path"):
> obj.set_path("spokes", self.paths["spokes"])
>
> + obj.setup(self.ENVIRONMENT)
> +
> self._app.schedule_screen(obj)
>
> def run(self):
> diff --git a/pyanaconda/ui/tui/hubs/__init__.py b/pyanaconda/ui/tui/hubs/__init__.py
> index 7d16ff3..73e3e62 100644
> --- a/pyanaconda/ui/tui/hubs/__init__.py
> +++ b/pyanaconda/ui/tui/hubs/__init__.py
> @@ -50,6 +50,7 @@ class TUIHub(TUIObject, common.Hub):
> self._keys = {} # holds spokes referenced by their user input key
> self._spoke_count = 0
>
> + def setup(self, environment = "anaconda"):
We don't use spaces around the '=' in default arguments.
> # look for spokes having category present in self.categories
> for c in self.categories:
> spokes = collect_spokes(self.paths["spokes"], c)
> @@ -57,10 +58,10 @@ class TUIHub(TUIObject, common.Hub):
> # sort them according to their priority
> for s in sorted(spokes, key = lambda s: s.priority):
> # Check if this spoke is to be shown in anaconda
> - if not s.should_run("anaconda", self.data):
> + if not s.should_run(environment, self.data):
> continue
> -
> - spoke = s(app, data, storage, payload, instclass)
> +
> + spoke = s(self.app, self.data, self.storage, self.payload, self.instclass)
> spoke.initialize()
>
> if not spoke.showable:
> diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py
> index 97a8c81..e3039d2 100644
> --- a/pyanaconda/ui/tui/simpleline/base.py
> +++ b/pyanaconda/ui/tui/simpleline/base.py
> @@ -344,6 +344,14 @@ class UIScreen(object):
> # list that holds the content to be printed out
> self._window = []
>
> + # index of the page (subset of screen) shown during show_all
> + # indexing starts with 0
> + self._page = 0
> +
> + def setup(self, environment):
> + """Do additional setup right before this screen is used."""
> + pass
> +
> def refresh(self, args = None):
> """Method which prepares the content desired on the screen to self._window.
>
Otherwise this looks good to me and I can confirm that it fixes a
traceback in text mode.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list