本文整理汇总了Python中env.Env.add_loaded_module方法的典型用法代码示例。如果您正苦于以下问题:Python Env.add_loaded_module方法的具体用法?Python Env.add_loaded_module怎么用?Python Env.add_loaded_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类env.Env
的用法示例。
在下文中一共展示了Env.add_loaded_module方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from env import Env [as 别名]
# 或者: from env.Env import add_loaded_module [as 别名]
#.........这里部分代码省略.........
versions.append(v)
# Print module together with all its version, in which
# the default version and the currently loaded version are
# marked specially
self.be.echo(' {m:{l}} {v}'.format(m=module.name+':',
l=maxlength+1, v=', '.join(versions)))
def is_loaded(self, name):
"""Return True if module `name` is loaded, else False."""
modname, _ = self.decode_name(name)
if modname in [modname for modname, _ in
map(self.decode_file, self.env.modloaded)]:
return True
else:
return False
def load_module(self, name):
"""Load module `name` if it is not yet loaded."""
# Get full path to module file
modfile = self.get_module_file(name)
# If module file was not found, return
if modfile is None:
return
# Otherwise, if module is already loaded, return
elif modfile in self.env.modloaded:
return
# Otherwise, parse module file for loading and add module to list of
# loaded modules
else:
if self.parser.load(modfile):
self.env.add_loaded_module(modfile)
def unload_module(self, name):
"""Unload module `name` if it is currently loaded."""
# Get module name and version
modname, modversion = self.decode_name(name)
# Get module file, name, and version from currently loaded modules
for modfile, (modnamefile, modversionfile) in zip(
self.env.modloaded,
map(self.decode_file, self.env.modloaded)):
# If module name matches, unload module and remove module from
# list of loaded modules
if modname == modnamefile and (
modversion is None or modversion == modversionfile):
if self.parser.unload(modfile):
self.env.modloaded.remove(modfile)
def process_modified(self):
"""Check all modified environment variables and unset/export them as
needed.
"""
# Iterate over all variables that were modified
for var in [var for var in self.env.variables.values()
if var.is_modified()]:
# Unset variable if it is marked for unset
if var.is_unset():
self.be.unset(var.get_name())
# Otherwise update its value
else:
self.be.export(*var.get_export())
def cmd_avail(self):