本文整理汇总了Python中module.Module.addKeywordArg方法的典型用法代码示例。如果您正苦于以下问题:Python Module.addKeywordArg方法的具体用法?Python Module.addKeywordArg怎么用?Python Module.addKeywordArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类module.Module
的用法示例。
在下文中一共展示了Module.addKeywordArg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_xml
# 需要导入模块: from module import Module [as 别名]
# 或者: from module.Module import addKeywordArg [as 别名]
#.........这里部分代码省略.........
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:
m = __import__("__builtin__")
className = parts[0]
if className == "NoneType":
arg_impl = None
else:
objName = getattr(m, className)
arg_val = kw_arg.childNodes[0].data.strip()
# print arg_val
if arg_type == "bool":
if str(arg_val).lower() == "false":
arg_impl = False
else:
arg_impl = True
else:
arg_impl = objName(arg_val)
# print "kw: %s, val: %s, type: %s" % (arg_keyword, arg_impl, arg_type)
module.addKeywordArg(arg_keyword, arg_impl)
workflow_list.append(module)
workflow_obj = Workflow(workflow_list, val_obj, stat_file, version)
return workflow_obj