本文整理汇总了Python中django.core.management.execute_from_command_line方法的典型用法代码示例。如果您正苦于以下问题:Python management.execute_from_command_line方法的具体用法?Python management.execute_from_command_line怎么用?Python management.execute_from_command_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management
的用法示例。
在下文中一共展示了management.execute_from_command_line方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_from_command_line
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def execute_from_command_line():
# Limit concurrency in all thread-pools to ONE.
from maasserver.utils import threads
threads.install_default_pool(maxthreads=1)
threads.install_database_unpool(maxthreads=1)
# Disable all database connections in the reactor.
from maasserver.utils import orm
from twisted.internet import reactor
assert not reactor.running, "The reactor has been started too early."
reactor.callFromThread(orm.disable_all_database_connections)
# Configure logging; Django is no longer responsible for this. Behave as
# if we're always at an interactive terminal (i.e. do not wrap stdout or
# stderr with log machinery).
from provisioningserver import logger
logger.configure(mode=logger.LoggingMode.COMMAND)
# Hand over to Django.
from django.core import management
management.execute_from_command_line()
示例2: runtests
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def runtests():
parsed_args, unparsed_args = parse_args()
only_wagtailmenus = r'^wagtailmenus(\.|$)'
if parsed_args.deprecation == 'all':
# Show all deprecation warnings from all packages
warnings.simplefilter('default', category=DeprecationWarning)
warnings.simplefilter('default', category=PendingDeprecationWarning)
elif parsed_args.deprecation == 'pending':
# Show all deprecation warnings
warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtailmenus)
warnings.filterwarnings('default', category=PendingDeprecationWarning, module=only_wagtailmenus)
elif parsed_args.deprecation == 'imminent':
# Show only imminent deprecation warnings
warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtailmenus)
elif parsed_args.deprecation == 'none':
# Deprecation warnings are ignored
pass
argv = [sys.argv[0], 'test'] + unparsed_args
return execute_from_command_line(argv)
示例3: test_call_cli
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def test_call_cli():
execute_from_command_line(["./manage.py", "testcmd"])
with pytest.raises(RuntimeError):
execute_from_command_line(["./manage.py", "testcmd", "--raise"])
示例4: test_django_verbosity
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def test_django_verbosity(capsys, manage):
# Make sure any command can be called, even if it does not explictly
# accept the --verbosity option
with pytest.raises(RuntimeError):
execute_from_command_line(
["./manage.py", "testcmd", "--raise", "--verbosity", "1"]
)
# Default
execute_from_command_line(["./manage.py", "ctxverbositycmd"])
out, err = capsys.readouterr()
assert out == "1"
# Explicit
execute_from_command_line(["./manage.py", "ctxverbositycmd", "--verbosity", "2"])
out, err = capsys.readouterr()
assert out == "2"
# Invalid
out = manage("ctxverbositycmd", "--verbosity", "4", ignore_errors=True)
out = out.replace(b"'", b'"') # may contain both single and double quotes
assert out == (
b"Usage: manage.py ctxverbositycmd [OPTIONS]\n"
b"\n"
b'Error: Invalid value for "-v" / "--verbosity": 4 is not in the '
b"valid range of 0 to 3.\n"
)
# Default (option)
execute_from_command_line(["./manage.py", "argverbositycommand"])
out, err = capsys.readouterr()
assert out == "1"
# Explicit (option)
execute_from_command_line(
["./manage.py", "argverbositycommand", "--verbosity", "2"]
)
out, err = capsys.readouterr()
assert out == "2"
示例5: test_django_help
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def test_django_help(manage):
# The -h/--help switches cause the program to exit. Invoking the command
# through execute_from_command_line would cause the test suite to exit as
# well... this means that we have to call it in a subprocess.
helps = [
manage("helpcmd", "-h"),
manage("helpcmd", "--help"),
manage("help", "helpcmd"),
]
assert len(set(helps)) == 1
help_text = helps[0]
assert b"HELP_CALLED" not in help_text
assert help_text.startswith(b"Usage: manage.py helpcmd ")
示例6: test_group_command
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def test_group_command(capsys):
execute_from_command_line(["./manage.py", "groupcmd"])
out, err = capsys.readouterr()
assert out == "group_command\n"
execute_from_command_line(["./manage.py", "groupcmd", "subcmd1"])
out, err = capsys.readouterr()
assert out == "group_command\nSUB1\n"
execute_from_command_line(["./manage.py", "groupcmd", "subcmd3"])
out, err = capsys.readouterr()
assert out == "group_command\nSUB2\n"
示例7: django_cmd
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def django_cmd(args: list):
if 'runserver' not in args:
# cd to "web" directory
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'web'))
elif len(args) <= 1:
bind_host = _get_bind_socket()
args.append(bind_host)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", WEB_PACKAGE + ".settings")
management.execute_from_command_line([EXEC_PATH + ' --django', ] + args)
示例8: run
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def run():
settings_path = os.path.join(os.getcwd(), 'deeru')
settings_py = os.path.join(settings_path, 'settings.py')
if os.path.exists(settings_py):
sys.path.insert(0, os.getcwd())
os.environ['DJANGO_SETTINGS_MODULE'] = 'deeru.settings'
else:
settings.configure(INSTALLED_APPS=['deeru_cmd.apps.DeerUCmdConfig'])
management.execute_from_command_line()
示例9: run_tests
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def run_tests(self):
from django.core import management
DSM = 'DJANGO_SETTINGS_MODULE'
if DSM not in os.environ:
os.environ[DSM] = 'trackstats.tests.settings'
management.execute_from_command_line()
示例10: execute_django_command
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def execute_django_command(cmd):
command = ['manage.py']
command.extend(cmd)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
return execute_from_command_line(command)
示例11: test_command_help
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def test_command_help(self):
with captured_stdout(), captured_stderr():
# `call_command` bypasses the parser; by calling
# `execute_from_command_line` with the help subcommand we
# ensure that there are no issues with the parser itself.
execute_from_command_line(['django-admin', 'help', 'makemessages'])
示例12: run_tests
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def run_tests(self):
from django.core import management
DSM = 'DJANGO_SETTINGS_MODULE'
if DSM not in os.environ:
os.environ[DSM] = 'actistream.tests.settings'
management.execute_from_command_line()
示例13: run_regiond_command
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def run_regiond_command(management, parser):
"""Called to run the regiond command.
The command itself is sys.argv[1] so that is not passed into this function.
"""
# At present, only root should execute regiond commands
if os.getuid() != 0:
raise SystemExit("You can only '%s' as root." % sys.argv[1])
management.execute_from_command_line()
示例14: run_django
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def run_django(is_snap, is_devenv):
# Force the production MAAS Django configuration.
if is_snap:
snap_data = os.environ["SNAP_DATA"]
os.environ.update(
{
"DJANGO_SETTINGS_MODULE": "maasserver.djangosettings.snappy",
"MAAS_PATH": os.environ["SNAP"],
"MAAS_ROOT": snap_data,
"MAAS_DATA": os.path.join(os.environ["SNAP_COMMON"], "maas"),
"MAAS_REGION_CONFIG": os.path.join(snap_data, "regiond.conf"),
"MAAS_DNS_CONFIG_DIR": os.path.join(snap_data, "bind"),
"MAAS_PROXY_CONFIG_DIR": os.path.join(snap_data, "proxy"),
"MAAS_SYSLOG_CONFIG_DIR": os.path.join(snap_data, "syslog"),
"MAAS_IMAGES_KEYRING_FILEPATH": (
"/snap/maas/current/usr/share/keyrings/"
"ubuntu-cloudimage-keyring.gpg"
),
"MAAS_THIRD_PARTY_DRIVER_SETTINGS": os.path.join(
os.environ["SNAP"], "etc/maas/drivers.yaml"
),
}
)
elif is_devenv:
os.environ[
"DJANGO_SETTINGS_MODULE"
] = "maasserver.djangosettings.development"
else:
os.environ[
"DJANGO_SETTINGS_MODULE"
] = "maasserver.djangosettings.settings"
# Let Django do the rest.
from django.core import management
management.execute_from_command_line()
示例15: django_admin
# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import execute_from_command_line [as 别名]
def django_admin(*args):
"""Executes a django admin tool from the app directory."""
cwd = os.getcwd()
os.chdir(os.environ['APP_DIR'])
management.execute_from_command_line(['django-admin.py'] + list(args))
os.chdir(cwd)