Beispiel #1
0
    def check_options(self):
        # django switched to argparse in version 1.8
        if DJANGO_VERSION >= (1, 8):
            parser = base.CommandParser(None,
                                        usage="%(prog)s subcommand [options] [args]",
                                        add_help=False)
            parser.add_argument('--settings')
            parser.add_argument('--pythonpath')
            parser.add_argument(CONFIGURATION_ARGUMENT,
                                help=CONFIGURATION_ARGUMENT_HELP)

            parser.add_argument('args', nargs='*')  # catch-all
            try:
                options, args = parser.parse_known_args(self.argv[2:])
                if options.configuration:
                    os.environ[self.namevar] = options.configuration
                base.handle_default_options(options)
            except base.CommandError:
                pass  # Ignore any option errors at this point.
        # django < 1.7 did use optparse
        else:
            from django.core.management import LaxOptionParser
            parser = LaxOptionParser(option_list=configuration_options,
                                     add_help_option=False)
            try:
                options, args = parser.parse_args(self.argv)
                if options.configuration:
                    os.environ[self.namevar] = options.configuration
            except:
                pass  # Ignore any option errors at this point.
    def check_options(self):
        try:
            parser = base.CommandParser(
                usage="%(prog)s subcommand [options] [args]", add_help=False)
        except TypeError:
            # Django before 2.1 used a `cmd` argument.
            parser = base.CommandParser(
                None,
                usage="%(prog)s subcommand [options] [args]",
                add_help=False)
        parser.add_argument('--settings')
        parser.add_argument('--pythonpath')
        parser.add_argument(CONFIGURATION_ARGUMENT,
                            help=CONFIGURATION_ARGUMENT_HELP)

        parser.add_argument('args', nargs='*')  # catch-all
        try:
            options, args = parser.parse_known_args(self.argv[2:])
            if options.configuration:
                os.environ[self.namevar] = options.configuration
            base.handle_default_options(options)
        except base.CommandError:
            pass  # Ignore any option errors at this point.