当前位置: 首页>>代码示例>>Python>>正文


Python GenericXML.get_children方法代码示例

本文整理汇总了Python中CIME.XML.generic_xml.GenericXML.get_children方法的典型用法代码示例。如果您正苦于以下问题:Python GenericXML.get_children方法的具体用法?Python GenericXML.get_children怎么用?Python GenericXML.get_children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CIME.XML.generic_xml.GenericXML的用法示例。


在下文中一共展示了GenericXML.get_children方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from CIME.XML.generic_xml import GenericXML [as 别名]
# 或者: from CIME.XML.generic_xml.GenericXML import get_children [as 别名]
    def __init__(self, machobj, infile=None, compiler=None, mpilib=None, files=None, version=None):
        """
        initialize an object
        """

        if infile is None:
            if files is None:
                files = Files()
            infile = files.get_value("COMPILERS_SPEC_FILE")
            schema = files.get_schema("COMPILERS_SPEC_FILE")

        GenericXML.__init__(self, infile, schema)
        self._machobj = machobj
        if version is not None:
            # this is used in scripts_regression_tests to force version 2, it should not be used otherwise
            self._version = version
        else:
            self._version = self.get_version()

        self.machine  = machobj.get_machine_name()
        self.os = machobj.get_value("OS")
        if compiler is None:
            compiler = machobj.get_default_compiler()
        self.compiler       = compiler

        if mpilib is None:
            if compiler is None:
                mpilib = machobj.get_default_MPIlib()
            else:
                mpilib = machobj.get_default_MPIlib(attributes={'compiler':compiler})
        self.mpilib = mpilib

        self.compiler_nodes = None # Listed from last to first
        #Append the contents of $HOME/.cime/config_compilers.xml if it exists
        #This could cause problems if node matchs are repeated when only one is expected
        infile = os.path.join(os.environ.get("HOME"),".cime","config_compilers.xml")
        if os.path.exists(infile):
            GenericXML.read(self, infile)

        if self.compiler is not None:
            self.set_compiler(compiler)

        if self._version > 1.0:
            schema_db = GenericXML(infile=schema)
            compiler_vars = schema_db.get_child("{http://www.w3.org/2001/XMLSchema}group", attributes={"name":"compilerVars"})
            choice  = schema_db.get_child(name="{http://www.w3.org/2001/XMLSchema}choice", root=compiler_vars)
            self.flag_vars = set(schema_db.get(elem, "name") for elem in schema_db.get_children(root=choice, attributes={"type":"flagsVar"}))
开发者ID:Katetc,项目名称:cime,代码行数:49,代码来源:compilers.py

示例2: _write_macros_file_v2

# 需要导入模块: from CIME.XML.generic_xml import GenericXML [as 别名]
# 或者: from CIME.XML.generic_xml.GenericXML import get_children [as 别名]
    def _write_macros_file_v2(self, build_system, output, xml=None):
        """Write a Macros file for this machine.

        Arguments:
        build_system - Format of the file to be written. Currently the only
                       valid values are "Makefile" and "CMake".
        output - Text I/O object (inheriting from io.TextIOBase) that
                 output should be written to. Typically, this will be the
                 Macros file, opened for writing.
        """
        # Set up writer for this build system.
        if build_system == "Makefile":
            writer = MakeMacroWriter(output)
        elif build_system == "CMake":
            writer = CMakeMacroWriter(output)
        else:
            expect(False,
                   "Unrecognized build system provided to write_macros: " +
                   build_system)

        # Start processing the file.
        value_lists = dict()
        node_list = []
        if xml is None:
            node_list = self.get_children(name="compiler")
        else:
            gen_xml = GenericXML()
            gen_xml.read_fd(xml)
            node_list = gen_xml.get_children(name="compiler")

        for compiler_elem in node_list:
            block = CompilerBlock(writer, compiler_elem, self._machobj, self)
            # If this block matches machine settings, use it.
            if block.matches_machine():
                block.add_settings_to_lists(self.flag_vars, value_lists)
        # Now that we've scanned through the input, output the variable
        # settings.
        vars_written = set()
        while value_lists:
            # Variables that are ready to be written.
            ready_variables = [
                var_name for var_name in value_lists
                if value_lists[var_name].depends <= vars_written
            ]
            expect(len(ready_variables) > 0,
                   "The file {} has bad <var> references. "
                   "Check for circular references or variables that "
                   "are in a <var> tag but not actually defined.".format(self.filename))
            big_normal_tree = None
            big_append_tree = None
            for var_name in ready_variables:
                # Note that we're writing this variable.
                vars_written.add(var_name)
                # Make the conditional trees and write them out.
                normal_tree, append_tree = \
                    value_lists[var_name].to_cond_trees()
                big_normal_tree = merge_optional_trees(normal_tree,
                                                        big_normal_tree)
                big_append_tree = merge_optional_trees(append_tree,
                                                        big_append_tree)
                # Remove this variable from the list of variables to handle
                # next iteration.
                del value_lists[var_name]
            if big_normal_tree is not None:
                big_normal_tree.write_out(writer)
            if big_append_tree is not None:
                big_append_tree.write_out(writer)
开发者ID:Katetc,项目名称:cime,代码行数:69,代码来源:compilers.py


注:本文中的CIME.XML.generic_xml.GenericXML.get_children方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。