Beispiel #1
0
    def loadAllDefaults(self):
        r"""Initializes all setting objects from the default files

        Crawls the res folder for all XML files, tries to load them as settings files
        and sets all default settings from there. (if there is a duplicate setting it
        will throw an error)

        Also grabs explicitly-defined Settings objects for framework settings.

        The formatting of the file name is important as it clues it in to what's valid.

        """
        for dirname, _dirnames, filenames in os.walk(armi.RES):
            for filename in filenames:
                if filename.lower().endswith("settings.xml"):
                    reader = settingsIO.SettingsDefinitionReader(self)
                    reader.readFromFile(os.path.join(dirname, filename))

        for fwSetting in fwSettings.getFrameworkSettings():
            self.settings[fwSetting.name] = fwSetting
Beispiel #2
0
    def getSettings(self) -> Dict[str, Setting]:
        """
        Return a dictionary containing all Settings defined by the framework and all plugins.
        """
        # Start with framework settings
        settingDefs = {
            setting.name: setting
            for setting in fwSettings.getFrameworkSettings()
        }

        # The optionsCache stores options that may have come from a plugin before the
        # setting to which they apply. Whenever a new setting is added, we check to see
        # if there are any options in the cache, popping them out and adding them to the
        # setting.  If all plugins' settings have been processed and the cache is not
        # empty, that's an error, because a plugin must have provided options to a
        # setting that doesn't exist.
        optionsCache: Dict[
            str, List[settings.Option]] = collections.defaultdict(list)
        defaultsCache: Dict[str, settings.Default] = {}

        for pluginSettings in self._pm.hook.defineSettings():
            for pluginSetting in pluginSettings:
                if isinstance(pluginSetting, settings.Setting):
                    name = pluginSetting.name
                    if name in settingDefs:
                        raise ValueError(
                            f"The setting {pluginSetting.name} "
                            "already exists and cannot be redefined.")
                    settingDefs[name] = pluginSetting
                    # handle when new setting has modifier in the cache (modifier loaded first)
                    if name in optionsCache:
                        settingDefs[name].addOptions(optionsCache.pop(name))
                    if name in defaultsCache:
                        settingDefs[name].changeDefault(
                            defaultsCache.pop(name))
                elif isinstance(pluginSetting, settings.Option):
                    if pluginSetting.settingName in settingDefs:
                        # modifier loaded after setting, so just apply it (no cache needed)
                        settingDefs[pluginSetting.settingName].addOption(
                            pluginSetting)
                    else:
                        # no setting yet, cache it and apply when it arrives
                        optionsCache[pluginSetting.settingName].append(
                            pluginSetting)
                elif isinstance(pluginSetting, settings.Default):
                    if pluginSetting.settingName in settingDefs:
                        # modifier loaded after setting, so just apply it (no cache needed)
                        settingDefs[pluginSetting.settingName].changeDefault(
                            pluginSetting)
                    else:
                        # no setting yet, cache it and apply when it arrives
                        defaultsCache[
                            pluginSetting.settingName] = pluginSetting
                else:
                    raise TypeError(
                        "Invalid setting definition found: {} ({})".format(
                            pluginSetting, type(pluginSetting)))

        if optionsCache:
            raise ValueError(
                "The following options were provided for settings that do "
                "not exist. Make sure that the set of active plugins is "
                "consistent.\n{}".format(optionsCache))

        if defaultsCache:
            raise ValueError(
                "The following defaults were provided for settings that do "
                "not exist. Make sure that the set of active plugins is "
                "consistent.\n{}".format(defaultsCache))

        return settingDefs
Beispiel #3
0
 def loadAllDefaults(self):
     r"""Initializes all setting objects from the default files
     """
     for fwSetting in fwSettings.getFrameworkSettings():
         self.settings[fwSetting.name] = fwSetting