python类execute_from_command_line()的实例源码

setup.py 文件源码 项目:django-actistream 作者: pennersr 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
__init__.py 文件源码 项目:maas 作者: maas 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
entrypoints.py 文件源码 项目:borgcube 作者: enkore 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def manage():
    from django.core.management import execute_from_command_line
    from .utils import hook
    _set_db_uri()
    logging.getLogger('borg.output.progress').setLevel('INFO')
    logging.getLogger('borg.output.stats').setLevel('INFO')
    hook.borgcube_startup(process='manage')
    sys.exit(execute_from_command_line())
setup.py 文件源码 项目:django-trackstats 作者: pennersr 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
cli.py 文件源码 项目:maas 作者: maas 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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()
docker_django_management.py 文件源码 项目:tts-bug-bounty-dashboard 作者: 18F 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def execute_from_command_line(argv):  # type: (List[str]) -> None
    '''
    This is like django.core.management.execute_from_command_line,
    but if the django package is unavailable, the script executes itself
    inside a docker container, where the django package is assumed
    to be available.

    Ultimately, this allows developers to use manage.py from their host
    system without needing to prefix all of their commands with
    'docker-compose run <container name>'.
    '''

    is_runserver = len(argv) > 1 and argv[1] == 'runserver'

    if IS_RUNNING_IN_DOCKER:
        if is_runserver:
            setup_docker_sigterm_handler()
        wait_for_db()

        if 'PYTHONUNBUFFERED' not in os.environ:
            warn("PYTHONUNBUFFERED is not defined. Some output may "
                 "not be visible.")

    try:
        from django.core.management import execute_from_command_line
    except ImportError as e:
        if not CONTAINER_NAME:
            raise e
        # Assume the user wants to run us in docker.
        if is_runserver:
            # Even with --service-ports, by default runserver only exposes
            # itself on 127.0.0.1, which docker can't expose to the
            # host through its networking stack. It's easiest to just
            # tell the developer to use 'docker-compose up' instead.
            warn("You should probably be using 'docker-compose up' "
                 "to run the server.")
        try:
            cmd_name = 'docker-compose'
            cmd_args = [
                cmd_name, 'run', CONTAINER_NAME, 'python'
            ] + argv

            if sys.platform == 'win32':
                # Windows doesn't support the exec() syscall,
                # so run docker-compose in a subshell.
                # This will allow stdio to work as expected.
                return_code = subprocess.call(cmd_args)
                sys.exit(return_code)
            else:
                os.execvp(cmd_name, cmd_args)
        except OSError:
            # Apparently docker-compose isn't installed, so just raise
            # the original ImportError.
            raise e

    execute_from_command_line(argv)


问题


面经


文章

微信
公众号

扫码关注公众号