我有以下用于迁移开发的fabfile.py
Django代码生产。
#--------------------------------------------------
# This script enable separation of development and production.
#--------------------------------------------------
from fabric.api import run, local, env, put, sudo
from fabric.contrib.project import rsync_project
env.hosts = ["bosswebserver"]
env.static_path = "/u33/app/www/coolapp/html/coolapp/"
env.app_path = "/u33/app/www/coolapp/wsgi-scripts/coolapp/"
def collect_static():
local('python manage.py collectstatic --noinput --settings=webframework.settings.dev')
def deploy_static():
rsync_project(local_dir='.static/.',
remote_dir=env.static_path,
delete=True,
extra_opts='--no-perms --no-times')
def deploy_app():
rsync_project(local_dir='.',
remote_dir=env.app_path,
delete=True,
exclude=['.static', 'user_files'],
extra_opts='--no-perms --no-times')
def migrate_db():
run('python {app_path}manage.py migrate --settings=webframework.settings.prod'.format(**env))
def restart_server():
run('sudo /usr/local/bin/httpd_restart')
def deploy():
collect_static()
deploy_static()
deploy_app()
migrate_db() # break here
restart_server()
现在我做的时候
$ fab deploy
我最后收到了这条消息:
webframework/settings/dev.py
webframework/settings/prod.py
sent 15.59K bytes received 160.09K bytes 117.12K bytes/sec
total size is 25.46M speedup is 144.92
[ bosswebserver] run: python /u33/app/www/coolapp/wsgi-scripts/coolapp/manage.py migrate --settings=webframework.settings.prod
Fatal error: run() received nonzero return code -1 while executing!
Requested: python /u33/app/www/coolapp/wsgi-scripts/coolapp/manage.py migrate --settings=webframework.settings.prod
Executed: /bin/bash -l -c "python /u33/app/www/coolapp/wsgi-scripts/coolapp/manage.py migrate --settings=webframework.settings.prod"
Aborting.
Disconnecting from bosswebserver... done.
我该如何解决这个问题?
更新:
我试过这个,通过在前面添加r
来实现它:
def migrate_db():
run(r'python /u33/app/www/coolapp/wsgi-scripts/coolapp/manage.py migrate --settings=webframework.settings.prod')
然而,我仍然为何失败感到困惑:
def migrate_db():
run('python {app_path}manage.py migrate --settings=webframework.settings.prod'.format(**env))