[anaconda:master 1/3] Factor computation of paths attribute into UserInterface class.
Vratislav Podzimek
vpodzime at redhat.com
Thu Dec 4 11:03:14 UTC 2014
On Tue, 2014-12-02 at 13:24 -0500, mulhern wrote:
> This is done mostly to eliminate setting a bunch of class attributes
> which only serve the purpose of local variables for computing the paths
> attribute.
>
> Make the newly created method static. It is necessary to get the value from
> __file__ from the file it actually resides in. The only thing that I can
> imagine that would be a class attribute is the ui_subdir, and I don't
> think the ui_subdir necessarily needs to be an attribute of the two
> UserInterface subclasses.
>
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
> pyanaconda/ui/__init__.py | 32 +++++++++++++++++++++++++++++---
> pyanaconda/ui/gui/__init__.py | 21 ++-------------------
> pyanaconda/ui/tui/__init__.py | 20 +-------------------
> 3 files changed, 32 insertions(+), 41 deletions(-)
>
> diff --git a/pyanaconda/ui/__init__.py b/pyanaconda/ui/__init__.py
> index 209f9a1..8aaae29 100644
> --- a/pyanaconda/ui/__init__.py
> +++ b/pyanaconda/ui/__init__.py
> @@ -23,6 +23,7 @@ __all__ = ["UserInterface"]
>
> import copy
> import os
> +import site
> from pyanaconda.ui.common import collect
>
> class PathDict(dict):
> @@ -72,9 +73,6 @@ class UserInterface(object):
> from pyanaconda.errors import errorHandler
> errorHandler.ui = self
>
> -
> - basepath = os.path.dirname(__file__)
> - basemask = "pyanaconda.ui"
> paths = PathDict({})
>
> @property
> @@ -82,6 +80,34 @@ class UserInterface(object):
> """Returns the number of tty the UserInterface is running on."""
> raise NotImplementedError
>
> + @staticmethod
> + def get_paths(basepath, ui_subdir):
> + """ Gets search path directory for user interface subclasses.
> +
> + :param str basepath: the directory of the subclass file
> + :param str ui_subdir: the subdirectory of ui ('gui' or 'tui')
> +
> + :returns: the PathDict object for the parameters specified.
> + :rtype: PathDict
> + """
> + BASEMASK = "pyanaconda.ui"
> + UPDATEPATH = "/tmp/updates/pyanaconda.ui"
> + sitepackages = [os.path.join(d, "pyanaconda", "ui")
> + for d in site.getsitepackages()]
> + pathlist = set([UPDATEPATH, basepath] + sitepackages)
> +
> + return UserInterface.paths + {
> + "categories": [(BASEMASK + ".categories.%s",
> + os.path.join(path, "categories"))
> + for path in pathlist],
> + "spokes": [(BASEMASK + "." + ui_subdir + ".spokes.%s",
> + os.path.join(path, ui_subdir, "spokes"))
> + for path in pathlist],
> + "hubs": [(BASEMASK + "." + ui_subdir + ".hubs.%s",
> + os.path.join(path, ui_subdir, "hubs"))
> + for path in pathlist]
> + }
> +
> @classmethod
> def update_paths(cls, pathdict):
> """Receives pathdict and appends it's contents to the current
> diff --git a/pyanaconda/ui/gui/__init__.py b/pyanaconda/ui/gui/__init__.py
> index 08c2573..690305d 100644
> --- a/pyanaconda/ui/gui/__init__.py
> +++ b/pyanaconda/ui/gui/__init__.py
> @@ -18,7 +18,7 @@
> #
> # Red Hat Author(s): Chris Lumens <clumens at redhat.com>
> #
> -import inspect, os, sys, time, site, signal
> +import inspect, os, sys, time, signal
> import meh.ui.gui
>
> from contextlib import contextmanager
> @@ -470,24 +470,7 @@ class GraphicalUserInterface(UserInterface):
> # we have a sensible initial value, just in case
> self._saved_help_button_label = _("Help!")
>
> - basemask = "pyanaconda.ui"
> - basepath = os.path.dirname(__file__)
> - updatepath = "/tmp/updates/pyanaconda/ui"
> - sitepackages = [os.path.join(dir, "pyanaconda", "ui")
> - for dir in site.getsitepackages()]
> - pathlist = set([updatepath, basepath] + sitepackages)
> -
> - paths = UserInterface.paths + {
> - "categories": [(basemask + ".categories.%s",
> - os.path.join(path, "categories"))
> - for path in pathlist],
> - "spokes": [(basemask + ".gui.spokes.%s",
> - os.path.join(path, "gui/spokes"))
> - for path in pathlist],
> - "hubs": [(basemask + ".gui.hubs.%s",
> - os.path.join(path, "gui/hubs"))
> - for path in pathlist]
> - }
> + paths = UserInterface.get_paths(os.path.dirname(__file__), "gui")
>
> def _assureLogoImage(self):
> # make sure there is a logo image present,
> diff --git a/pyanaconda/ui/tui/__init__.py b/pyanaconda/ui/tui/__init__.py
> index 0fb1ca7..2ca9a67 100644
> --- a/pyanaconda/ui/tui/__init__.py
> +++ b/pyanaconda/ui/tui/__init__.py
> @@ -30,7 +30,6 @@ from pyanaconda.ui.tui.tuiobject import YesNoDialog, ErrorDialog
>
> import os
> import sys
> -import site
> import Queue
> import meh.ui.text
> import logging
> @@ -99,24 +98,7 @@ class TextUserInterface(ui.UserInterface):
> self.isFinal = isFinal
> self.quitMessage = quitMessage
>
> - basemask = "pyanaconda.ui"
> - basepath = os.path.dirname(__file__)
> - updatepath = "/tmp/updates/pyanaconda/ui"
> - sitepackages = [os.path.join(dir, "pyanaconda", "ui")
> - for dir in site.getsitepackages()]
> - pathlist = set([updatepath, basepath] + sitepackages)
> -
> - paths = ui.UserInterface.paths + {
> - "categories": [(basemask + ".categories.%s",
> - os.path.join(path, "categories"))
> - for path in pathlist],
> - "spokes": [(basemask + ".tui.spokes.%s",
> - os.path.join(path, "tui/spokes"))
> - for path in pathlist],
> - "hubs": [(basemask + ".tui.hubs.%s",
> - os.path.join(path, "tui/hubs"))
> - for path in pathlist]
> - }
> + paths = ui.UserInterface.get_paths(os.path.dirname(__file__), "tui")
>
> @property
> def tty_num(self):
This requires the same changes in initial-setup.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list