当前位置: 首页>>代码示例>>Python>>正文


Python management.execute_from_command_line方法代码示例

本文整理汇总了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() 
开发者ID:maas,项目名称:maas,代码行数:24,代码来源:__init__.py

示例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) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:23,代码来源:runtests.py

示例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"]) 
开发者ID:GaretJax,项目名称:django-click,代码行数:6,代码来源:test_adapter.py

示例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" 
开发者ID:GaretJax,项目名称:django-click,代码行数:41,代码来源:test_adapter.py

示例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 ") 
开发者ID:GaretJax,项目名称:django-click,代码行数:16,代码来源:test_adapter.py

示例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" 
开发者ID:GaretJax,项目名称:django-click,代码行数:14,代码来源:test_adapter.py

示例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) 
开发者ID:offensive-hub,项目名称:black-widow,代码行数:11,代码来源:manage.py

示例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() 
开发者ID:gojuukaze,项目名称:DeerU,代码行数:13,代码来源:deeru_admin.py

示例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() 
开发者ID:pennersr,项目名称:django-trackstats,代码行数:8,代码来源:setup.py

示例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) 
开发者ID:ZedObaia,项目名称:django-pyqt,代码行数:15,代码来源:manage.py

示例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']) 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_extraction.py

示例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() 
开发者ID:pennersr,项目名称:django-actistream,代码行数:8,代码来源:setup.py

示例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() 
开发者ID:maas,项目名称:maas,代码行数:11,代码来源:cli.py

示例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() 
开发者ID:maas,项目名称:maas,代码行数:38,代码来源:region_script.py

示例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) 
开发者ID:google,项目名称:personfinder,代码行数:8,代码来源:update_messages.py


注:本文中的django.core.management.execute_from_command_line方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。