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


Python Env.get_modloaded_str方法代码示例

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


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

示例1: __init__

# 需要导入模块: from env import Env [as 别名]
# 或者: from env.Env import get_modloaded_str [as 别名]

#.........这里部分代码省略.........

    def cmd_help(self):
        """Command 'help': show help on commands or modules."""
        # Get help topic from arguments and parse for commands
        topic = self.args[0] if len(self.args) > 0 else None
        command, alternatives = self.parse_command(topic)

        # If no topic was specified, show usage information
        if self.cmd in ['--help'] or topic is None:
            self.print_help('usage')
        # If a command was specified, print its help file
        elif command in ['help']:
            self.print_help(os.path.join('commands', 'help'))
        elif command in ['avail', 'status']:
            self.print_help(os.path.join('commands', 'avail'))
        elif command in ['config']:
            self.print_help(os.path.join('commands', 'config'))
        elif command in ['list']:
            self.print_help(os.path.join('commands', 'list'))
        elif command in ['load']:
            self.print_help(os.path.join('commands', 'load'))
        elif command in ['unload']:
            self.print_help(os.path.join('commands', 'unload'))
        # If no command was determined but there are alternatives, show a list
        # of ambiguous commands
        elif command is None and len(alternatives) > 0:
            self.be.error("Command '{c}' is ambiguous. See 'modm help'.".format(
                          c=topic))
            self.be.echo()
            self.be.echo("Did you mean one of these?")
            for a in alternatives:
                self.be.echo("  {u}[{t}]".format(
                    u=a[0:len(self.cmd)+1], t=a[len(self.cmd)+1:]))
        # Otherwise, check modules for help
        else:
            self.init_modules()
            index = self.find_module(topic)

            # If no module was found with the name `topic`, show error
            if index is None:
                self.be.error("Unknown help topic '{t}'.".format(t=topic))
                self.be.error("See 'modm help help' for a list of help topics.")
            # Otherwise show error if no help file was set for the module
            elif self.modules[index].help_file is None:
                self.be.error("No help available for module '{m}'.".format(
                    m=self.modules[index].name))
            # Otherwise (help file was found for module), print help file
            else:
                self.print_file(self.modules[index].help_file)

    def cmd_list(self):
        """Command 'list': show all currently loaded modules."""
        self.init_modules()

        # Print all loaded modules in an easily parsable list
        for modfile in natsorted(self.env.modloaded):
            head, modversion = os.path.split(modfile)
            _, modname = os.path.split(head)
            self.be.echo(os.path.join(modname, modversion))

    def cmd_load(self):
        """Command 'load': load all specified module files."""
        self.init_modules()
        self.init_parser()

        # Try to load each argument as a module
        for name in self.args:
            index = self.find_module(name, strict=True)
            # If module was found, load it
            if index is not None:
                # If a version of the module is currently loaded, unload it
                if self.is_loaded(name):
                    self.unload_module(self.decode_name(name)[0])
                self.load_module(name)
            # Otherwise print error
            else:
                self.be.error("Module '{m}' not found.".format(m=name))

        # After loading all modules, act on all environment variables that
        # have changed
        self.process_modified()
        self.be.export(self.env.modloaded_var, self.env.get_modloaded_str())

    def cmd_unload(self):
        """Command 'unload': unload all specified module files."""
        self.init_modules()
        self.init_parser()

        # Unload each argument
        for name in self.args:
            self.unload_module(name)

        # After unloadig all modules, act on all environment variables that
        # have changed
        self.process_modified()
        self.be.export(self.env.modloaded_var, self.env.get_modloaded_str())

    def cmd_version(self):
        """Print version information."""
        self.be.echo("modm version {v}".format(v=__version__))
开发者ID:jhedev,项目名称:modm,代码行数:104,代码来源:modm.py


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