예제 #1
0
파일: common.py 프로젝트: rvykydal/anaconda
def collect_categories(mask_paths, displaymode):
    """Return a list of all category subclasses. Look for them in modules
       imported as module_mask % basename(f) where f is name of all files in path.
    """
    categories = []
    if displaymode == DISPLAY_MODE_TEXT:
        for mask, path in mask_paths:
            categories.extend(collect(mask, path, lambda obj: getattr(obj, "displayOnHubTUI", None) is not None))
    else:
        for mask, path in mask_paths:
            categories.extend(collect(mask, path, lambda obj: getattr(obj, "displayOnHubGUI", None) is not None))

    return categories
예제 #2
0
    def _collectActionClasses(module_pattern_w_path, standalone_class):
        """Collect all the Hub and Spoke classes which should be enqueued for processing.

        :param module_pattern_w_path: the full name patterns (pyanaconda.ui.gui.spokes.%s)
                                      and directory paths to modules we are about to import
        :type module_pattern_w_path: list of (string, string)

        :param standalone_class: the parent type of Spokes we want to pick up
        :type standalone_class: common.StandaloneSpoke based types

        :return: list of Spoke classes with standalone_class as a parent
        :rtype: list of Spoke classes
        """
        standalones = []

        def check_standalone_spokes(obj):
            return issubclass(obj, standalone_class) and \
                getattr(obj, "preForHub", False) or \
                getattr(obj, "postForHub", False)

        for module_pattern, path in module_pattern_w_path:
            standalones.extend(
                collect(module_pattern,
                        path,
                        check_standalone_spokes)
            )

        return standalones
예제 #3
0
파일: common.py 프로젝트: rvykydal/anaconda
def collect_spokes(mask_paths, category):
    """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:
        candidate_spokes = (collect(mask, path,
                            lambda obj: hasattr(obj, "category") and obj.category is not None and obj.category.__name__ == category))
        # filter out any spokes from the candidates that have already been visited by the user before
        # (eq. before Anaconda or Initial Setup started) and should not be visible again
        visible_spokes = []
        for candidate in candidate_spokes:
            if screen_access.sam.get_screen_visited(candidate.__name__):
                log.info("Spoke %s will not be displayed because it has already been visited before.",
                         candidate.__name__)
            else:
                visible_spokes.append(candidate)
        spokes.extend(visible_spokes)

    return spokes
예제 #4
0
def collect_spokes(mask_paths, category):
    """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:
        candidate_spokes = (collect(
            mask, path, lambda obj: hasattr(obj, "category") and obj.category
            is not None and obj.category.__name__ == category))
        # filter out any spokes from the candidates that have already been visited by the user before
        # (eq. before Anaconda or Initial Setup started) and should not be visible again
        visible_spokes = []
        for candidate in candidate_spokes:
            if screen_access.sam.get_screen_visited(candidate.__name__):
                log.info(
                    "Spoke %s will not be displayed because it has already been visited before.",
                    candidate.__name__)
            else:
                visible_spokes.append(candidate)
        spokes.extend(visible_spokes)

    return spokes
예제 #5
0
def collect_categories(mask_paths, displaymode):
    """Return a list of all category subclasses. Look for them in modules
       imported as module_mask % basename(f) where f is name of all files in path.
    """
    categories = []
    if displaymode == DISPLAY_MODE_TEXT:
        for mask, path in mask_paths:
            categories.extend(
                collect(
                    mask, path, lambda obj: getattr(obj, "displayOnHubTUI",
                                                    None) is not None))
    else:
        for mask, path in mask_paths:
            categories.extend(
                collect(
                    mask, path, lambda obj: getattr(obj, "displayOnHubGUI",
                                                    None) is not None))

    return categories
예제 #6
0
def collect_categories(mask_paths):
    """Return a list of all category subclasses. Look for them in modules
       imported as module_mask % basename(f) where f is name of all files in path.
    """
    categories = []

    for mask, path in mask_paths:
        categories.extend(collect(mask, path, lambda obj: issubclass(obj, SpokeCategory)))

    return categories
예제 #7
0
    def _get_available_classes(self, paths):
        """Return a list of available install classes."""
        # Append the location of install classes to the python path
        # so install classes can import and inherit correct classes.
        sys.path = paths + sys.path

        classes = set()
        for path in paths:
            log.debug("Searching %s.", path)

            for install_class in collect("%s", path, self._is_install_class):
                log.debug("Found %s.", self._get_class_description(install_class))
                classes.add(install_class)

        # Classes are sorted by their priority and name in the reversed order,
        # so classes with the highest priority and longer name are preferred.
        # For example, Fedora Workstation doesn't have higher priority.
        return sorted(classes, key=self._get_install_class_key, reverse=True)
예제 #8
0
    def _get_available_classes(self, paths):
        """Return a list of available install classes."""
        # Append the location of install classes to the python path
        # so install classes can import and inherit correct classes.
        sys.path = paths + sys.path

        classes = set()
        for path in paths:
            log.debug("Searching %s.", path)

            for install_class in collect("%s", path, self._is_install_class):
                log.debug("Found %s.", self._get_class_description(install_class))
                classes.add(install_class)

        # Classes are sorted by their priority and name in the reversed order,
        # so classes with the highest priority and longer name are preferred.
        # For example, Fedora Workstation doesn't have higher priority.
        return sorted(classes, key=self._get_install_class_key, reverse=True)
예제 #9
0
    def __init__(self,
                 addon_paths=None,
                 commandUpdates=None,
                 dataUpdates=None):
        if addon_paths is None:
            addon_paths = []

        if commandUpdates is None:
            commandUpdates = commandMap

        if dataUpdates is None:
            dataUpdates = dataMap

        super().__init__(commandUpdates=commandUpdates,
                         dataUpdates=dataUpdates)
        self.onPart = {}

        # collect all kickstart addons for anaconda to addons dictionary
        # which maps addon_id to it's own data structure based on BaseData
        # with execute method
        addons = {}

        # collect all AddonData subclasses from
        # for p in addon_paths: <p>/<plugin id>/ks/*.(py|so)
        # and register them under <plugin id> name
        for module_name, path in addon_paths:
            addon_id = os.path.basename(os.path.dirname(os.path.abspath(path)))
            if not os.path.isdir(path):
                continue

            classes = util.collect(
                module_name, path,
                lambda cls: issubclass(cls, self.AddonClassType))
            if classes:
                addons[addon_id] = classes[0](name=addon_id)

        # Prepare the final structures for 3rd party addons
        self.addons = AddonRegistry(addons)

        # The %anaconda section uses its own handler for a limited set of commands
        self.anaconda = AnacondaSectionHandler()

        # The %packages section is handled by the DBus module.
        self.packages = UselessObject()
예제 #10
0
    def _collectActionClasses(self, module_pattern_w_path, standalone_class):
        """Collect all the Hub and Spoke classes which should be enqueued for processing.

        :param module_pattern_w_path: the full name patterns (pyanaconda.ui.gui.spokes.%s)
                                      and directory paths to modules we are about to import
        :type module_pattern_w_path: list of (string, string)

        :param standalone_class: the parent type of Spokes we want to pick up
        :type standalone_class: common.StandaloneSpoke based types

        :return: list of Spoke classes with standalone_class as a parent
        :rtype: list of Spoke classes
        """
        standalones = []

        for module_pattern, path in module_pattern_w_path:
            standalones.extend(collect(module_pattern, path, lambda obj: issubclass(obj, standalone_class) and \
                                       getattr(obj, "preForHub", False) or getattr(obj, "postForHub", False)))

        return standalones
예제 #11
0
    def __init__(self, addon_paths=None, commandUpdates=None, dataUpdates=None):
        if addon_paths is None:
            addon_paths = []

        if commandUpdates is None:
            commandUpdates = commandMap

        if dataUpdates is None:
            dataUpdates = dataMap

        super().__init__(commandUpdates=commandUpdates, dataUpdates=dataUpdates)
        self.onPart = {}

        # collect all kickstart addons for anaconda to addons dictionary
        # which maps addon_id to it's own data structure based on BaseData
        # with execute method
        addons = {}

        # collect all AddonData subclasses from
        # for p in addon_paths: <p>/<plugin id>/ks/*.(py|so)
        # and register them under <plugin id> name
        for module_name, path in addon_paths:
            addon_id = os.path.basename(os.path.dirname(os.path.abspath(path)))
            if not os.path.isdir(path):
                continue

            classes = util.collect(module_name, path,
                                   lambda cls: issubclass(cls, self.AddonClassType))
            if classes:
                addons[addon_id] = classes[0](name=addon_id)

        # Prepare the final structures for 3rd party addons
        self.addons = AddonRegistry(addons)

        # The %anaconda section uses its own handler for a limited set of commands
        self.anaconda = AnacondaSectionHandler()
예제 #12
0
from pyanaconda.core.util import collect

# FIXME: Storage tests don't want to work right now, so they are disabled while
# I debug them so we can get useful data from other tests.
os._exit(77)

if os.geteuid() != 0:
    sys.stderr.write("You must be root to run the storage tests; skipping.\n")
    # This return code tells the automake test driver that this test was skipped.
    os._exit(77)

if "top_srcdir" not in os.environ:
    sys.stderr.write("$top_srcdir must be defined in the test environment\n")
    # This return code tells the automake test driver that the test setup failed
    sys.exit(99)

failures = 0

classes = collect(
    "cases.%s",
    os.path.abspath(
        os.path.join(os.environ["top_srcdir"], "tests/storage/cases/")),
    lambda obj: getattr(obj, "desc", None) is not None)

for tc in classes:
    obj = tc()
    failures += obj.run()

os._exit(failures)
예제 #13
0
import os, sys

from pyanaconda.core.util import collect

# FIXME: Storage tests don't want to work right now, so they are disabled while
# I debug them so we can get useful data from other tests.
os._exit(77)

if os.geteuid() != 0:
    sys.stderr.write("You must be root to run the storage tests; skipping.\n")
    # This return code tells the automake test driver that this test was skipped.
    os._exit(77)

if "top_srcdir" not in os.environ:
    sys.stderr.write("$top_srcdir must be defined in the test environment\n")
    # This return code tells the automake test driver that the test setup failed
    sys.exit(99)

failures = 0

classes = collect("cases.%s",
                  os.path.abspath(os.path.join(os.environ["top_srcdir"], "tests/storage/cases/")),
                  lambda obj: getattr(obj, "desc", None) is not None)

for tc in classes:
    obj = tc()
    failures += obj.run()

os._exit(failures)