本文整理汇总了Python中CIME.XML.machines.Machines.get_module_system_cmd_path方法的典型用法代码示例。如果您正苦于以下问题:Python Machines.get_module_system_cmd_path方法的具体用法?Python Machines.get_module_system_cmd_path怎么用?Python Machines.get_module_system_cmd_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIME.XML.machines.Machines
的用法示例。
在下文中一共展示了Machines.get_module_system_cmd_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EnvModule
# 需要导入模块: from CIME.XML.machines import Machines [as 别名]
# 或者: from CIME.XML.machines.Machines import get_module_system_cmd_path [as 别名]
class EnvModule(object):
# TODO - write env_mach_specific files into case
# Public API
def __init__(self, machine, compiler, cimeroot, caseroot, mpilib, debug=False):
self._machine = Machines(machine=machine)
self._compiler = compiler
self._cimeroot = cimeroot
self._caseroot = caseroot
self._mpilib = mpilib
self._debug = debug
self._module_system = self._machine.get_module_system_type()
def load_env_for_case(self):
mach_specific = EnvMachSpecific(caseroot=self._caseroot)
module_nodes = mach_specific.get_node("modules")
env_nodes = mach_specific.get_node("environment_variables")
if (module_nodes is not None):
modules_to_load = self._compute_module_actions(module_nodes)
self.load_modules(modules_to_load)
if (env_nodes is not None):
envs_to_set = self._compute_env_actions(env_nodes)
self.load_envs(envs_to_set)
def load_modules(self, modules_to_load):
if (self._module_system == "module"):
self._load_module_modules(modules_to_load)
elif (self._module_system == "soft"):
self._load_soft_modules(modules_to_load)
elif (self._module_system == "dotkit"):
self._load_dotkit_modules(modules_to_load)
elif (self._module_system == "none"):
self._load_none_modules(modules_to_load)
else:
expect(False, "Unhandled module system '%s'" % self._module_system)
def load_envs(self, envs_to_set):
for env_name, env_value in envs_to_set:
# Let bash do the work on evaluating and resolving env_value
os.environ[env_name] = run_cmd("echo %s" % env_value)
# Private API
def _compute_module_actions(self, module_nodes):
return self._compute_actions(module_nodes, "command")
def _compute_env_actions(self, env_nodes):
return self._compute_actions(env_nodes, "env")
def _compute_actions(self, nodes, child_tag):
result = [] # list of tuples ("name", "argument")
for node in nodes:
if (self._match_attribs(node.attrib)):
for child in node:
expect(child.tag == child_tag, "Expected %s element" % child_tag)
result.append( (child.get("name"), child.text) )
return result
def _match_attribs(self, attribs):
if ("compiler" in attribs and
not self._match(self._compiler, attribs["compiler"])):
return False
elif ("mpilib" in attribs and
not self._match(self._mpilib, attribs["mpilib"])):
return False
elif ("debug" in attribs and
not self._match("TRUE" if self._debug else "FALSE", attribs["debug"].upper())):
return False
return True
def _match(self, my_value, xml_value):
if (xml_value.startswith("!")):
return my_value != xml_value[1:]
else:
return my_value == xml_value
def _load_module_modules(self, modules_to_load):
python_mod_cmd = self._machine.get_module_system_cmd_path("python")
for action, argument in modules_to_load:
cmd = "%s %s %s" % (python_mod_cmd, action, argument)
py_module_code = run_cmd(cmd)
exec(py_module_code)
def _load_soft_modules(self, modules_to_load):
expect(False, "Not yet implemented")
def _load_dotkit_modules(self, modules_to_load):
expect(False, "Not yet implemented")
def _load_none_modules(self, modules_to_load):
expect(False, "Not yet implemented")