本文整理匯總了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: runtests
點讚 6
# 需要導入模塊: 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)
開發者ID:rkhleics,項目名稱:wagtailmenus,代碼行數:23,
示例2: execute_from_command_line
點讚 6
# 需要導入模塊: 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()
開發者ID:maas,項目名稱:maas,代碼行數:24,
示例3: test_call_cli
點讚 5
# 需要導入模塊: 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"])
開發者ID:GaretJax,項目名稱:django-click,代碼行數:6,
示例4: test_django_verbosity
點讚 5
# 需要導入模塊: 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"
開發者ID:GaretJax,項目名稱:django-click,代碼行數:41,
示例5: test_django_help
點讚 5
# 需要導入模塊: 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 ")
開發者ID:GaretJax,項目名稱:django-click,代碼行數:16,
示例6: test_group_command
點讚 5
# 需要導入模塊: 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"
開發者ID:GaretJax,項目名稱:django-click,代碼行數:14,
示例7: django_cmd
點讚 5
# 需要導入模塊: 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)
開發者ID:offensive-hub,項目名稱:black-widow,代碼行數:11,
示例8: run
點讚 5
# 需要導入模塊: 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()
開發者ID:gojuukaze,項目名稱:DeerU,代碼行數:13,
示例9: run_tests
點讚 5
# 需要導入模塊: 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()
開發者ID:pennersr,項目名稱:django-trackstats,代碼行數:8,
示例10: execute_django_command
點讚 5
# 需要導入模塊: 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)
開發者ID:ZedObaia,項目名稱:django-pyqt,代碼行數:15,
示例11: test_command_help
點讚 5
# 需要導入模塊: 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'])
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,
示例12: run_tests
點讚 5
# 需要導入模塊: 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()
開發者ID:pennersr,項目名稱:django-actistream,代碼行數:8,
示例13: run_regiond_command
點讚 5
# 需要導入模塊: 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()
開發者ID:maas,項目名稱:maas,代碼行數:11,
示例14: run_django
點讚 5
# 需要導入模塊: 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()
開發者ID:maas,項目名稱:maas,代碼行數:38,
示例15: django_admin
點讚 5
# 需要導入模塊: 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)
開發者ID:google,項目名稱:personfinder,代碼行數:8,
注:本文中的django.core.management.execute_from_command_line方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。