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)
docker_django_management.py 文件源码
python
阅读 42
收藏 0
点赞 0
评论 0
评论列表
文章目录