Python django.core.management.base.BaseCommand.option_list() Examples
The following are 9
code examples of django.core.management.base.BaseCommand.option_list().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.management.base.BaseCommand
, or try the search function
.
Example #1
Source File: compat.py From django-sitemessage with BSD 3-Clause "New" or "Revised" License | 5 votes |
def options_getter(command_options): """Compatibility function to get rid of optparse in management commands after Django 1.10. :param tuple command_options: tuple with `CommandOption` objects. """ def get_options(option_func=None): from optparse import make_option from django.core.management.base import BaseCommand func = option_func or make_option options = tuple([func(*option.args, **option.kwargs) for option in command_options]) if option_func is None: if VERSION < (1, 8): result = BaseCommand.option_list + options else: result = [] else: result = options return result return get_options
Example #2
Source File: runmodwsgi.py From scylla with Apache License 2.0 | 5 votes |
def add_arguments(self, parser): ignore = set(['const', 'callback', 'callback_args', 'callback_kwargs']) types = { 'int': int, 'string': str } for option in mod_wsgi.server.option_list: opts = option._short_opts + option._long_opts kwargs = {} for attr in option.ATTRS: if attr not in ignore and hasattr(option, attr): if attr == 'type': if getattr(option, attr) in types: kwargs[attr] = types[getattr(option, attr)] elif attr == 'default': if getattr(option, attr) != ('NO', 'DEFAULT'): kwargs[attr] = getattr(option, attr) else: if getattr(option, attr) is not None: kwargs[attr] = getattr(option, attr) if (kwargs.get('action') == 'callback' and option.callback.__name__ == 'check_percentage'): del kwargs['action'] kwargs['type'] = check_percentage if kwargs.get('nargs') == 1: del kwargs['nargs'] parser.add_argument(*opts, **kwargs)
Example #3
Source File: translate_messages.py From django-autotranslate with MIT License | 5 votes |
def add_arguments(self, parser): # Previously, only the standard optparse library was supported and # you would have to extend the command option_list variable with optparse.make_option(). # See: https://docs.djangoproject.com/en/1.8/howto/custom-management-commands/#accepting-optional-arguments # In django 1.8, these custom options can be added in the add_arguments() parser.add_argument('--locale', '-l', default=[], dest='locale', action='append', help='autotranslate the message files for the given locale(s) (e.g. pt_BR). ' 'can be used multiple times.') parser.add_argument('--untranslated', '-u', default=False, dest='skip_translated', action='store_true', help='autotranslate the fuzzy and empty messages only.') parser.add_argument('--set-fuzzy', '-f', default=False, dest='set_fuzzy', action='store_true', help='set the fuzzy flag on autotranslated messages.')
Example #4
Source File: test.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def create_parser(self, prog_name, subcommand): test_runner_class = get_runner(settings, self.test_runner) options = self.option_list + getattr( test_runner_class, 'option_list', ()) return OptionParser(prog=prog_name, usage=self.usage(subcommand), version=self.get_version(), option_list=options)
Example #5
Source File: __init__.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def call_command(name, *args, **options): """ Calls the given command, with the given options and args/kwargs. This is the primary API you should use for calling specific commands. Some examples: call_command('syncdb') call_command('shell', plain=True) call_command('sqlall', 'myapp') """ # Load the command object. try: app_name = get_commands()[name] except KeyError: raise CommandError("Unknown command: %r" % name) if isinstance(app_name, BaseCommand): # If the command is already loaded, use it directly. klass = app_name else: klass = load_command_class(app_name, name) # Grab out a list of defaults from the options. optparse does this for us # when the script runs from the command line, but since call_command can # be called programatically, we need to simulate the loading and handling # of defaults (see #10080 for details). defaults = {} for opt in klass.option_list: if opt.default is NO_DEFAULT: defaults[opt.dest] = None else: defaults[opt.dest] = opt.default defaults.update(options) return klass.execute(*args, **defaults)
Example #6
Source File: _base.py From django-dbbackup with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, *args, **kwargs): self.option_list = self.base_option_list + self.option_list if django.VERSION < (1, 10): options = tuple([optparse_make_option(*_args, **_kwargs) for _args, _kwargs in self.option_list]) self.option_list = options + BaseCommand.option_list super(BaseDbBackupCommand, self).__init__(*args, **kwargs)
Example #7
Source File: _base.py From django-dbbackup with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_arguments(self, parser): for args, kwargs in self.option_list: kwargs = dict([ (k, v) for k, v in kwargs.items() if not k.startswith('_') and k not in USELESS_ARGS]) parser.add_argument(*args, **kwargs)
Example #8
Source File: _base.py From esdc-ce with Apache License 2.0 | 5 votes |
def __init__(self, **kwargs): if self.options: self.option_list = self.__class__.option_list + self.options super(DanubeCloudCommand, self).__init__(**kwargs)
Example #9
Source File: __init__.py From luscan-devel with GNU General Public License v2.0 | 4 votes |
def execute(self): """ Given the command-line arguments, this figures out which subcommand is being run, creates a parser appropriate to that command, and runs it. """ # Preprocess options to extract --settings and --pythonpath. # These options could affect the commands that are available, so they # must be processed early. parser = LaxOptionParser(usage="%prog subcommand [options] [args]", version=get_version(), option_list=BaseCommand.option_list) self.autocomplete() try: options, args = parser.parse_args(self.argv) handle_default_options(options) except: pass # Ignore any option errors at this point. try: subcommand = self.argv[1] except IndexError: subcommand = 'help' # Display help if no arguments were given. if subcommand == 'help': if len(args) <= 2: parser.print_lax_help() sys.stdout.write(self.main_help_text() + '\n') elif args[2] == '--commands': sys.stdout.write(self.main_help_text(commands_only=True) + '\n') else: self.fetch_command(args[2]).print_help(self.prog_name, args[2]) elif subcommand == 'version': sys.stdout.write(parser.get_version() + '\n') # Special-cases: We want 'django-admin.py --version' and # 'django-admin.py --help' to work, for backwards compatibility. elif self.argv[1:] == ['--version']: # LaxOptionParser already takes care of printing the version. pass elif self.argv[1:] in (['--help'], ['-h']): parser.print_lax_help() sys.stdout.write(self.main_help_text() + '\n') else: self.fetch_command(subcommand).run_from_argv(self.argv)