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


Python CommandParser.add_option方法代码示例

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


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

示例1: execute

# 需要导入模块: from django.core.management.base import CommandParser [as 别名]
# 或者: from django.core.management.base.CommandParser import add_option [as 别名]
    def execute(self, argv=None, stdout=None, stderr=None):

        if argv is None:
            argv = sys.argv

        if stdout is None:
            stdout = sys.stdout

        if stderr is None:
            stderr = sys.stderr

        if django.VERSION >= (1, 8):
            from django.core.management.base import CommandParser
            parser = CommandParser(None,
                usage="%(prog)s subcommand [options] [args]",
                add_help=False)
            parser.add_argument('--version', action='store_true', help="show program's version number and exit")
            parser.add_argument('-h', '--help', action='store_true', help="show this help message and exit")

            try:
                options, argv = parser.parse_known_args(argv)
            except:
                pass  # Ignore any option errors at this point.
        else:
            from django.core.management import LaxOptionParser

            parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
                option_list=(),
                add_help_option=False)
            parser.add_option('--version', action='store_true', help="show program's version number and exit")
            parser.add_option('-h', '--help', action='store_true', help="show this help message and exit")

            try:
                options, argv = parser.parse_args(argv)
            except:
                pass  # Ignore any option errors at this point.

        if len(argv) > 1:
            subcommand = argv[1]
        else:
            subcommand = 'help'  # Display help if no arguments were given.


        if options.help:

            if subcommand == 'help':
                if hasattr(parser, 'print_lax_help'):
                    parser.print_lax_help()
                else:
                    parser.print_help(stdout)
                stdout.write(self.main_help_text() + '\n')
            else:
                command = self.fetch_command(subcommand)
                if command is not None:
                    command.print_help(self.prog_name, subcommand, file=stdout)
                else:
                    stdout.write(self.unknown_command_text(subcommand) + '\n')

        elif subcommand == 'version' or options.version:

            stdout.write(wirecloud.platform.__version__ + '\n')

        elif subcommand == 'help':

            if len(argv) <= 2:
                if hasattr(parser, 'print_lax_help'):
                    parser.print_lax_help()
                else:
                    parser.print_help(stdout)
                stdout.write(self.main_help_text() + '\n')
            elif argv[2] == '--commands':
                stdout.write(self.main_help_text(commands_only=True) + '\n')
            else:
                command = self.fetch_command(argv[2])
                if command is not None:
                    command.print_help(self.prog_name, argv[2], file=stdout)
                else:
                    stdout.write(self.unknown_command_text(argv[2]) + '\n')

        else:
            command = self.fetch_command(subcommand)
            if command is not None:
                command.run_from_argv(argv, stdout=stdout, stderr=stderr)
            else:
                stdout.write(self.unknown_command_text(subcommand) + '\n')
开发者ID:rachmadagitam,项目名称:apps.Wirecloud,代码行数:87,代码来源:wirecloud_admin.py


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