And move them to a common file to avoid code duplication.
Cherry-picked from commit 1276f37cf107defc68aa8d0bc5f9b3a2b0c4046.
Related: rhbz#1128616 --- initial_setup/common.py | 54 +++++++++++++++++++++++++++++ initial_setup/gui/hubs/initial_setup_hub.py | 42 ++-------------------- initial_setup/tui/hubs/initial_setup_hub.py | 5 +++ 3 files changed, 62 insertions(+), 39 deletions(-) create mode 100644 initial_setup/common.py
diff --git a/initial_setup/common.py b/initial_setup/common.py new file mode 100644 index 0000000..2009128 --- /dev/null +++ b/initial_setup/common.py @@ -0,0 +1,54 @@ +"""Common methods for Initial Setup""" + +from pyanaconda.ui.common import collect +from pyanaconda.constants import FIRSTBOOT_ENVIRON + +def collect_spokes(mask_paths, spoke_parent_class): + """Return a list of all spoke subclasses that should appear for a given + category. Look for them in files imported as module_path % basename(f) + + :param mask_paths: list of mask, path tuples to search for classes + :type mask_paths: list of (mask, path) + + :param spoke_parent_class: Spoke parent class used for checking spoke compatibility + :type spoke_parent_class: GUI or TUI Spoke class + + :return: list of Spoke classes belonging to category + :rtype: list of Spoke classes + + """ + spokes = [] + for mask, path in mask_paths: + + spokes.extend(collect(mask, path, + lambda obj: issubclass(obj, spoke_parent_class) and obj.should_run("firstboot", None))) + return spokes + + +def collectCategoriesAndSpokes(hub_instance, spoke_parent_class): + """Collects categories and spokes to be displayed on this Hub, + this method overrides the Anacondas implementation so that + spokes relevant to Initial setup are collected + + :param hub_instance: an Initial Setup GUI or TUI Hub class instance + :type hub_instance: class instance + + :param spoke_parent_class: Spoke parent class used for checking spoke compatibility + :type spoke_parent_class: GUI or TUI Spoke class + + :return: dictionary mapping category class to list of spoke classes + :rtype: dictionary[category class] -> [ list of spoke classes ] + """ + ret = {} + + # Collect all the categories this hub displays, then collect all the + # spokes belonging to all those categories. + candidate_spokes = collect_spokes(hub_instance.paths["spokes"], spoke_parent_class) + spokes = [spoke for spoke in candidate_spokes + if spoke.should_run(FIRSTBOOT_ENVIRON, hub_instance.data)] + + for spoke in spokes: + ret.setdefault(spoke.category, []) + ret[spoke.category].append(spoke) + + return ret diff --git a/initial_setup/gui/hubs/initial_setup_hub.py b/initial_setup/gui/hubs/initial_setup_hub.py index 19aab55..9df65ab 100644 --- a/initial_setup/gui/hubs/initial_setup_hub.py +++ b/initial_setup/gui/hubs/initial_setup_hub.py @@ -1,31 +1,13 @@ from pyanaconda.constants import FIRSTBOOT_ENVIRON from pyanaconda.ui.gui.hubs import Hub -from pyanaconda.ui.gui.spokes import Spoke -from pyanaconda.ui.common import collect +from pyanaconda.ui.gui.spokes import Spoke as GUI_spoke_class from initial_setup import product +from initial_setup import common import os import sys
__all__ = ["InitialSetupMainHub"]
-def collect_spokes(mask_paths): - """Return a list of all spoke subclasses that should appear for a given - category. Look for them in files imported as module_path % basename(f) - - :param mask_paths: list of mask, path tuples to search for classes - :type mask_paths: list of (mask, path) - - :return: list of Spoke classes belonging to category - :rtype: list of Spoke classes - - """ - spokes = [] - for mask, path in mask_paths: - spokes.extend(collect(mask, path, - lambda obj: issubclass(obj, Spoke) and obj.should_run("firstboot", None))) - - return spokes -
class InitialSetupMainHub(Hub): uiFile = "initial_setup.glade" @@ -38,25 +20,7 @@ class InitialSetupMainHub(Hub): self._environs = [FIRSTBOOT_ENVIRON]
def _collectCategoriesAndSpokes(self): - """collects categories and spokes to be displayed on this Hub - - :return: dictionary mapping category class to list of spoke classes - :rtype: dictionary[category class] -> [ list of spoke classes ] - """ - - ret = {} - - # Collect all the categories this hub displays, then collect all the - # spokes belonging to all those categories. - candidate_spokes = collect_spokes(self.paths["spokes"]) - spokes = [spoke for spoke in candidate_spokes \ - if spoke.should_run(FIRSTBOOT_ENVIRON, self.data)] - - for spoke in spokes: - ret.setdefault(spoke.category, []) - ret[spoke.category].append(spoke) - - return ret + return common.collectCategoriesAndSpokes(self, GUI_spoke_class)
def _createBox(self): Hub._createBox(self) diff --git a/initial_setup/tui/hubs/initial_setup_hub.py b/initial_setup/tui/hubs/initial_setup_hub.py index 021a48a..a1ec2c3 100644 --- a/initial_setup/tui/hubs/initial_setup_hub.py +++ b/initial_setup/tui/hubs/initial_setup_hub.py @@ -1,6 +1,8 @@ from pyanaconda.constants import FIRSTBOOT_ENVIRON from pyanaconda.ui.tui.hubs import TUIHub +from pyanaconda.ui.tui.spokes import Spoke as TUI_spoke_class from initial_setup import product +from initial_setup import common import gettext
__all__ = ["InitialSetupMainHub"] @@ -21,3 +23,6 @@ class InitialSetupMainHub(TUIHub): def __init__(self, *args): TUIHub.__init__(self, *args) self._environs = [FIRSTBOOT_ENVIRON] + + def _collectCategoriesAndSpokes(self): + return common.collectCategoriesAndSpokes(self, TUI_spoke_class)