Exemplo n.º 1
0
    def _readYaml(self, stream, handleInvalids=True):
        """
        Read settings from a YAML stream.

        Notes
        -----
        This is intended to replace the XML stuff as we converge on consistent input formats.
        """
        from armi.physics.thermalHydraulics import const  # avoid circular import

        yaml = YAML()
        tree = yaml.load(stream)
        if "settings" not in tree:
            raise exceptions.InvalidSettingsFileError(
                self.inputPath,
                "Missing the `settings:` header required in YAML settings",
            )
        if const.ORIFICE_SETTING_ZONE_MAP in tree:
            raise exceptions.InvalidSettingsFileError(
                self.inputPath, "Appears to be an orifice_settings file"
            )
        caseSettings = tree[Roots.CUSTOM]
        self.inputVersion = tree["metadata"][Roots.VERSION]
        for settingName, settingVal in caseSettings.items():
            self._applySettings(settingName, settingVal)
Exemplo n.º 2
0
    def _readXml(self, stream, handleInvalids=True):
        """
        Read user settings from XML stream.
        """
        warnings.warn(
            "Loading from XML-format settings files is being deprecated.",
            DeprecationWarning,
        )
        tree = ET.parse(stream)
        settingRoot = tree.getroot()
        if Roots.VERSION in settingRoot.attrib:
            self.inputVersion = settingRoot.attrib[Roots.VERSION]

        if settingRoot.tag != self.rootTag:
            # checks to make sure the right kind of settings XML file
            # is being applied to the right class
            if settingRoot.tag == geometry.SystemLayoutInput.ROOT_TAG:
                customMsg = (
                    "\nSettings file appears to be a reactor geometry file. "
                    "Please provide a valid settings file."
                )
            else:
                customMsg = '\nRoot tag "{}" does not match expected value "{}"'.format(
                    settingRoot.tag, self.rootTag
                )
            raise exceptions.InvalidSettingsFileError(
                self.inputPath, customMsgEnd=customMsg
            )

        for settingElement in list(settingRoot):
            self._interpretSetting(settingElement)

        if handleInvalids:
            self._resolveProblems()
Exemplo n.º 3
0
    def readFromFile(self, path, handleInvalids=True):
        """Load file and read it."""

        with open(path, "r") as f:
            # make sure that we can actually open the file before trying to guess its
            # format. This will yield better error messages when things go awry.
            ext = os.path.splitext(path)[1].lower()
            self.format = self.FORMAT_FROM_EXT[ext]
            self.inputPath = path
            try:
                self.readFromStream(f, handleInvalids, self.format)
            except Exception as ee:
                raise exceptions.InvalidSettingsFileError(path, str(ee))