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


Python Env.add_loaded_module方法代码示例

本文整理汇总了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):
开发者ID:jhedev,项目名称:modm,代码行数:70,代码来源:modm.py


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