示例#1
0
    def testFindIncludes(self):
        includes = textProcessors.findYamlInclusions(
            pathlib.Path(RES_DIR) / "root.yaml")
        for i, _mark in includes:
            self.assertTrue(i.exists())

        self.assertEqual(len(includes), 2)
示例#2
0
    def _listInputFiles(cs):
        """
        Gathers information about the input files of this case.

        Returns
        -------
        inputInfo : list
            (label, fileName, shaHash) tuples
        """

        pathToLoading = pathlib.Path(cs.inputDirectory) / cs["loadingFile"]

        if pathToLoading.is_file():
            includedBlueprints = [
                inclusion[0]
                for inclusion in textProcessors.findYamlInclusions(pathToLoading)
            ]
        else:
            includedBlueprints = []

        inputInfo = []
        inputFiles = (
            [
                ("Case Settings", cs.caseTitle + ".yaml"),
                ("Blueprints", cs["loadingFile"]),
            ]
            + [("Included blueprints", inclBp) for inclBp in includedBlueprints]
            + [("Geometry", cs["geomFile"])]
        )

        activeInterfaces = interfaces.getActiveInterfaceInfo(cs)
        for klass, kwargs in activeInterfaces:
            if not kwargs.get("enabled", True):
                # Don't consider disabled interfaces
                continue
            interfaceFileNames = klass.specifyInputs(cs)
            for label, fileNames in interfaceFileNames.items():
                for fName in fileNames:
                    inputFiles.append((label, fName))

        if cs["reloadDBName"] and cs["runType"] == RunTypes.SNAPSHOTS:
            inputFiles.append(("Database", cs["reloadDBName"]))
        for label, fName in inputFiles:
            shaHash = (
                "MISSING"
                if (not fName or not os.path.exists(fName))
                else utils.getFileSHA1Hash(fName, digits=10)
            )
            inputInfo.append((label, fName, shaHash))

        return inputInfo
示例#3
0
文件: case.py 项目: ntouran/armi
    def clone(self, additionalFiles=None, title=None, modifiedSettings=None):
        """
        Clone existing ARMI inputs to current directory with optional settings modifications.

        Since each case depends on multiple inputs, this is a safer way to move cases
        around without having to wonder if you copied all the files appropriately.

        Parameters
        ----------
        additionalFiles : list (optional)
            additional file paths to copy to cloned case
        title : str (optional)
            title of new case
        modifiedSettings : dict (optional)
            settings to set/modify before creating the cloned case

        Raises
        ------
        RuntimeError
            If the source and destination are the same

        """
        cloneCS = self.cs.duplicate()

        if modifiedSettings is not None:
            cloneCS = cloneCS.modified(newSettings=modifiedSettings)

        clone = Case(cloneCS)
        clone.cs.path = pathTools.armiAbsPath(title or self.title) + ".yaml"

        if pathTools.armiAbsPath(clone.cs.path) == pathTools.armiAbsPath(
                self.cs.path):
            raise RuntimeError(
                "The source file and destination file are the same: {}\n"
                "Cannot use armi-clone to modify armi settings file.".format(
                    pathTools.armiAbsPath(clone.cs.path)))

        newSettings = copyInterfaceInputs(self.cs, clone.cs.inputDirectory)
        newCs = clone.cs.modified(newSettings=newSettings)
        clone.cs = newCs

        runLog.important("writing settings file {}".format(clone.cs.path))
        clone.cs.writeToYamlFile(clone.cs.path)
        runLog.important("finished writing {}".format(clone.cs))

        fromPath = lambda fname: pathTools.armiAbsPath(self.cs.inputDirectory,
                                                       fname)

        for inputFileSetting in ["loadingFile", "geomFile"]:
            fileName = self.cs[inputFileSetting]
            if fileName:
                pathTools.copyOrWarn(
                    inputFileSetting,
                    fromPath(fileName),
                    os.path.join(clone.cs.inputDirectory, fileName),
                )
            else:
                runLog.warning(
                    "skipping {}, there is no file specified".format(
                        inputFileSetting))

        with open(self.cs["loadingFile"], "r") as f:
            # The root for handling YAML includes is relative to the YAML file, not the
            # settings file
            root = (pathlib.Path(self.cs.inputDirectory) /
                    pathlib.Path(self.cs["loadingFile"]).parent)
            cloneRoot = (pathlib.Path(clone.cs.inputDirectory) /
                         pathlib.Path(clone.cs["loadingFile"]).parent)
            for includePath, mark in textProcessors.findYamlInclusions(
                    f, root=root):
                if not includePath.is_absolute():
                    includeSrc = root / includePath
                    includeDest = cloneRoot / includePath
                else:
                    # don't bother copying absolute files
                    continue
                if not includeSrc.exists():
                    raise OSError(
                        "The input file file `{}` referenced at {} does not exist."
                        .format(includeSrc, mark))
                pathTools.copyOrWarn(
                    "auxiliary input file `{}` referenced at {}".format(
                        includeSrc, mark),
                    includeSrc,
                    includeDest,
                )

        for fileName in additionalFiles or []:
            pathTools.copyOrWarn("additional file", fromPath(fileName),
                                 clone.cs.inputDirectory)

        return clone