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


Python Module.setName方法代码示例

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


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

示例1: parse_xml

# 需要导入模块: from module import Module [as 别名]
# 或者: from module.Module import setName [as 别名]
def parse_xml(xml_path):
    """
    This function parses a file with XML containing a Broadband
    workflow. It returns a workflow object.
    """
    workflow_list = []
    stat_file = ""
    version = ""
    val_obj = None
    dom_rep = xml.parse(xml_path)
    val_elements = dom_rep.getElementsByTagName("Validation_Run")
    if len(val_elements) > 0:
        val_element = val_elements[0]
        val_name = val_element.getAttribute("event")
        val_obj = getattr(validation_cfg.VE_EVENTS, val_name)
        version = val_element.getAttribute("version")

        stat_file = val_element.getAttribute("input_station_file")
        # Expand any variables that we find
        stat_file = expand_variables(stat_file)

    val_elements = dom_rep.getElementsByTagName("Scenario_Run")
    if len(val_elements) > 0:
        val_element = val_elements[0]
        version = val_element.getAttribute("version")
        stat_file = val_element.getAttribute("input_station_file")
        # Expand any variables that we find
        stat_file = expand_variables(stat_file)

    modules_element = dom_rep.getElementsByTagName("BBP_Modules")[0]
    # Print modules_element
    for mod in modules_element.childNodes:
        # BBP Module level
        if not mod.nodeType == mod.ELEMENT_NODE:
            continue
        # print mod
        module = Module()
        name_node = mod.getElementsByTagName("name")[0]
        name = name_node.childNodes[0].data.strip()
        # print name
        module.setName(name)
        files = mod.getElementsByTagName("staged_files")[0]
        for file_node in files.getElementsByTagName("file"):
            stage_file = file_node.childNodes[0].data.strip()
            # Expand any variables that we find
            stage_file = expand_variables(stage_file)

            module.addStageFile(stage_file)
        arguments = mod.getElementsByTagName("arguments")[0]
        for arg in arguments.getElementsByTagName("argument"):
            arg_type = arg.getAttribute("type")
            if not arg_type == "":
                parts = arg_type.split('.')
                if len(parts) > 1:
                    package = parts[0]
                    className = parts[1]
                    m = __import__(package)
                    objName = getattr(m, className)
                    arg_val = arg.childNodes[0].data.strip()
                    #print arg_val
                    arg_impl = getattr(objName, arg_val)
                else:
                    m = __import__("__builtin__")
                    className = parts[0]
                    if className == "NoneType":
                        arg_impl = None
                    elif className == "dict":
                        arg_impl = ast.literal_eval(arg.childNodes[0].data.strip())
                    else:
                        objName = getattr(m, className)
                        # Handle the empty string case
                        if not arg.childNodes:
                            arg_val = ""
                        else:
                            arg_val = arg.childNodes[0].data.strip()
                        #print arg_val
                        arg_impl = objName(arg_val)
                if isinstance(arg_impl, str):
                    # Expand any variables that we have
                    arg_impl = expand_variables(arg_impl)
                module.addArg(arg_impl)
            else:
                arg_val = arg.childNodes[0].data.strip()
                module.addArg(arg_val)
        kw_args = mod.getElementsByTagName("keyword_arguments")
        if len(kw_args) > 0:
            for kw_arg in kw_args[0].getElementsByTagName("keyword_argument"):
                arg_keyword = str(kw_arg.getAttribute("keyword"))
                arg_type = kw_arg.getAttribute("type")
                if not arg_type == "":
                    parts = arg_type.split('.')
                    if len(parts) > 1:
                        package = parts[0]
                        className = parts[1]
                        m = __import__(package)
                        objName = getattr(m, className)
                        arg_val = kw_arg.childNodes[0].data.strip()
                        #print arg_val
                        arg_impl = getattr(objName, arg_val)
                    else:
#.........这里部分代码省略.........
开发者ID:SCECcode,项目名称:BBP,代码行数:103,代码来源:xml_handler.py


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