本文整理汇总了Python中django.core.management.ManagementUtility.fetch_command方法的典型用法代码示例。如果您正苦于以下问题:Python ManagementUtility.fetch_command方法的具体用法?Python ManagementUtility.fetch_command怎么用?Python ManagementUtility.fetch_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management.ManagementUtility
的用法示例。
在下文中一共展示了ManagementUtility.fetch_command方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: report_data
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
def report_data(dumper):
"""
Fetches data from management commands and reports it to dumper.
:type dumper _xml.XmlDumper
:param dumper: destination to report
"""
utility = ManagementUtility()
for command_name in get_commands().keys():
try:
command = utility.fetch_command(command_name)
except ImproperlyConfigured:
continue # TODO: Log somehow
assert isinstance(command, BaseCommand)
use_argparse = False
try:
use_argparse = command.use_argparse
except AttributeError:
pass
dumper.start_command(command_name=command_name,
command_help_text=str(command.usage("").replace("%prog", command_name)))
module_to_use = _argparse if use_argparse else _optparse # Choose appropriate module: argparse, optparse
module_to_use.process_command(dumper, command, command.create_parser("", command_name))
dumper.close_command()
示例2: handle
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
def handle(self, *args, **options):
"""
Run and profile the specified management command with the provided
arguments.
"""
if not len(args):
self.print_help(sys.argv[0], 'profile')
sys.exit(1)
if not options['sort'] and not options['path']:
self.stdout.write('Output file path is required for call graph generation')
sys.exit(1)
command_name = args[0]
utility = ManagementUtility(sys.argv)
command = utility.fetch_command(command_name)
parser = command.create_parser(sys.argv[0], command_name)
command_options, command_args = parser.parse_args(list(args[1:]))
if command_name == 'test' and settings.TEST_RUNNER == 'django_nose.NoseTestSuiteRunner':
# Ugly hack: make it so django-nose won't have nosetests choke on
# our parameters
BaseCommand.option_list += self.custom_options
if options['backend'] == 'yappi':
import yet_another_django_profiler.yadp_yappi as yadp_yappi
profiler = yadp_yappi.YappiProfile()
else:
profiler = cProfile.Profile()
atexit.register(output_results, profiler, options, self.stdout)
profiler.runcall(call_command, command_name, *command_args, **command_options.__dict__)
sys.exit(0)
示例3: runtests
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
def runtests(*test_args):
parent = os.path.dirname(os.path.abspath(__file__))
os.environ['DJANGO_SETTINGS_MODULE'] = 'consent.tests.settings'
sys.path.insert(0, parent)
from django.core.management import ManagementUtility
utility = ManagementUtility()
command = utility.fetch_command('test')
command.execute(verbosity=1)
sys.exit()
示例4: handle
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
def handle(self, *args, **options):
"""
Run and profile the specified management command with the provided
arguments.
"""
if not self.use_argparse and not len(args):
self.print_help(sys.argv[0], 'profile')
sys.exit(1)
if not options['sort'] and not options['path']:
self.stdout.write('Output file path is required for call graph generation')
sys.exit(1)
if self.use_argparse:
command_name = options['other_command']
else:
command_name = args[0]
utility = ManagementUtility(sys.argv)
command = utility.fetch_command(command_name)
parser = command.create_parser(sys.argv[0], command_name)
if self.use_argparse:
command_options = parser.parse_args(options['command_arguments'])
command_args = vars(command_options).pop('args', ())
else:
command_options, command_args = parser.parse_args(list(args[1:]))
if command_name == 'test' and django_settings.TEST_RUNNER == 'django_nose.NoseTestSuiteRunner':
# Ugly hack: make it so django-nose won't have nosetests choke on
# our parameters
BaseCommand.option_list += self.custom_options
if options['backend'] == 'yappi' or (settings.YADP_PROFILER_BACKEND == 'yappi' and not options['backend']):
import yet_another_django_profiler.yadp_yappi as yadp_yappi
profiler = yadp_yappi.YappiProfile(wall=options['clock'] == 'wall')
else:
profiler = cProfile.Profile()
if 'testing' not in options:
atexit.register(output_results, profiler, options, self.stdout)
profiler.runcall(call_command, command_name, *command_args, stderr=self.stderr,
stdout=self.stdout, **vars(command_options))
if 'testing' in options:
output_results(profiler, options, self.stdout)
else:
sys.exit(0)
示例5: report_data
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
def report_data(dumper):
"""
Fetches data from management commands and reports it to dumper.
:type dumper _xml.XmlDumper
:param dumper: destination to report
"""
utility = ManagementUtility()
for command_name in get_commands().keys():
try:
command = utility.fetch_command(command_name)
except ImproperlyConfigured:
continue # TODO: Log somehow
assert isinstance(command, BaseCommand)
dumper.start_command(command_name=command_name,
command_help_text=str(command.usage("").replace("%prog", command_name)),
# TODO: support subcommands
command_args_text=str(command.args))
for opt in command.option_list:
num_of_args = int(opt.nargs) if opt.nargs else 0
opt_type = None
if num_of_args > 0:
# If option accepts arg, we need to determine its type. It could be int, choices, or something other
# See https://docs.python.org/2/library/optparse.html#standard-option-types
if opt.type in ["int", "long"]:
opt_type = "int"
elif opt.choices:
assert isinstance(opt.choices, list), "Choices should be list"
opt_type = opt.choices
# There is no official way to access this field, so I use protected one. At least it is public API.
# noinspection PyProtectedMember
dumper.add_command_option(
long_opt_names=opt._long_opts,
short_opt_names=opt._short_opts,
help_text=opt.help,
argument_info=(num_of_args, opt_type) if num_of_args else None)
dumper.close_command()
示例6: report_data
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
def report_data(dumper):
"""
Fetches data from management commands and reports it to dumper.
:type dumper _xml.XmlDumper
:param dumper: destination to report
"""
utility = ManagementUtility()
for command_name in get_commands().keys():
try:
command = utility.fetch_command(command_name)
except Exception as e:
sys.stderr.write("Error fetching command {0}: {1}\n".format(command_name, e))
continue
assert isinstance(command, BaseCommand)
use_argparse = False
try:
use_argparse = command.use_argparse
except AttributeError:
pass
try:
parser = command.create_parser("", command_name)
except Exception as e:
sys.stderr.write("Error parsing command {0}: {1}\n".format(command_name, e))
continue
dumper.start_command(
command_name=command_name,
command_help_text=VersionAgnosticUtils().to_unicode(command.usage("")).replace("%prog", command_name),
)
module_to_use = _argparse if use_argparse else _optparse # Choose appropriate module: argparse, optparse
module_to_use.process_command(dumper, command, parser)
dumper.close_command()
示例7: setup_environ
# 需要导入模块: from django.core.management import ManagementUtility [as 别名]
# 或者: from django.core.management.ManagementUtility import fetch_command [as 别名]
import time
import sys
import os
sys.path.append(os.getcwd()+"/site-packages")
sys.path.append(os.getcwd())
from django.core.management import setup_environ, ManagementUtility
import settings
setup_environ(settings)
if __name__ == '__main__':
utility = ManagementUtility()
command = utility.fetch_command('runwsgiserver')
command.execute(use_reloader=False)