本文整理汇总了Python中django.core.management.base.BaseCommand.option_list方法的典型用法代码示例。如果您正苦于以下问题:Python BaseCommand.option_list方法的具体用法?Python BaseCommand.option_list怎么用?Python BaseCommand.option_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management.base.BaseCommand
的用法示例。
在下文中一共展示了BaseCommand.option_list方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: options_getter
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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
示例2: add_arguments
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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)
示例3: add_arguments
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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.')
示例4: create_parser
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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)
示例5: call_command
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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)
示例6: __init__
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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)
示例7: add_arguments
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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)
示例8: __init__
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
def __init__(self, **kwargs):
if self.options:
self.option_list = self.__class__.option_list + self.options
super(DanubeCloudCommand, self).__init__(**kwargs)
示例9: execute
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import option_list [as 别名]
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)