Example #1
0
    def _interpretSetting(self, settingElement):
        settingName = settingElement.tag
        attributes = settingElement.attrib
        if settingName in self.settingsAlreadyRead:
            raise exceptions.SettingException(
                "The setting {} has been specified more than once in {}. Adjust input."
                "".format(settingName, self.inputPath))
        # add here, before it gets converted by name cleaning below.
        self.settingsAlreadyRead.add(settingName)
        if settingName in settingsRules.OLD_TAGS:
            # name cleaning
            settingName = settingElement.attrib["key"].replace(" ", "")
            values = list(settingElement)
            if not values:
                attributes = {
                    "type": settingsRules.OLD_TAGS[settingElement.tag]
                }
                if "val" in settingElement.attrib:
                    attributes["value"] = settingElement.attrib["val"]
                else:
                    # means this item has no children and no value, no reason for it to exist.
                    return
            else:
                attributes["value"] = [
                    subElement.attrib["val"] for subElement in values
                ]
                attributes["containedType"] = settingsRules.OLD_TAGS[
                    settingElement.attrib["type"]]

        elif "value" not in attributes:
            raise exceptions.SettingException(
                "No value supplied for the setting {} in {}".format(
                    settingName, self.inputPath))

        self._applySettings(settingName, attributes["value"])
Example #2
0
    def __init__(self, settings: Dict[str, Setting]):
        self._currentNames: Set[str] = set()
        self._activeRenames: Dict[str, str] = dict()
        self._expiredRenames: Set[Tuple[str, str, datetime.date]] = set()

        today = datetime.date.today()

        for name, s in settings.items():
            self._currentNames.add(name)
            for oldName, expiry in s.oldNames:
                if expiry is not None:
                    expired = expiry <= today
                else:
                    expired = False
                if expired:
                    self._expiredRenames.add((oldName, name, expiry))
                else:
                    if oldName in self._activeRenames:
                        raise exceptions.SettingException(
                            "The setting rename from {0}->{1} collides with another "
                            "rename {0}->{2}".format(
                                oldName, name, self._activeRenames[oldName]
                            )
                        )
                    self._activeRenames[oldName] = name
Example #3
0
    def _interpretSetting(self, settingElement):
        settingName = settingElement.tag
        attributes = settingElement.attrib

        if "type" not in attributes or "default" not in attributes:
            raise exceptions.InvalidSettingDefinition(settingName, attributes)

        default = attributes["default"]  # always a string at this point
        settingValues = self.applyConversions(settingName, default)
        # check for a new error conditions
        for correctedName, correctedDefault in settingValues.items():
            if correctedName != settingName:
                raise exceptions.SettingException(
                    "Settings definition file {} contained setting named {},\n"
                    "but it was changed to {}.".format(
                        self.inputPath, settingName, correctedName
                    )
                )
            if correctedDefault != default:
                # problem here when default is like, an string empty list '[]'
                # and it gets corrected to a real list. So hack:
                if default != "[]":
                    raise exceptions.SettingException(
                        "Settings definition file {} contained setting named {}, "
                        "but the value was changed from {} to {}. Change default "
                        "something that does not get auto-corrected.".format(
                            self.inputPath,
                            settingName,
                            repr(default),
                            repr(correctedDefault),
                        )
                    )
            if settingName.lower() in self._occupied_names:
                raise exceptions.SettingNameCollision(
                    'Duplicate definition for the setting "{}" found in {}.'.format(
                        settingName, self.inputPath
                    )
                )

        # everything is good, time to create an actual setting object
        self.cs.settings[settingName] = setting.Setting.factory(settingName, attributes)
        self._occupied_names.add(settingName.lower())