Python fabric无法在Django环境中使用
我在本地系统中有一个fabric文件,我正在使用它在远程服务器(virtualenv)中部署代码,并希望对其进行测试。方法定义如下所示Python fabric无法在Django环境中使用,python,django,linux,virtualenv,fabric,Python,Django,Linux,Virtualenv,Fabric,我在本地系统中有一个fabric文件,我正在使用它在远程服务器(virtualenv)中部署代码,并希望对其进行测试。方法定义如下所示 def test_deploy(gitid = '930bfc4'): # manually put the commit id at the end path = '/tmp/testapp/app1/source/demo4' with cd(path): commit_id =
def test_deploy(gitid = '930bfc4'):
# manually put the commit id at the end
path = '/tmp/testapp/app1/source/demo4'
with cd(path):
commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
# change the settings.py file and update the database
run (commit_id)
run ('cat .git/FETCH_HEAD')
path1 = '/tmp/testvehic/vehic'
with cd(path1):
run ('pwd')
env.activate = 'source /tmp/testapp/app1/bin/activate'
run ('python /tmp/testapp/app1/source/demo4/manage.py test')`
这表明
ImportError:没有名为django.core.management的模块
在谷歌搜索了一段时间后,我才知道它实际上并没有找到我的django环境。我的虚拟环境路径是
/tmp/testapp/app1
源代码位于
/tmp/testapp/app1/source/app1/
当我在服务器终端中运行命令
python manage.py test
时,它工作正常。如何通过fabric进行测试?我从下面的链接中得到了答案
我的代码片段现在如下所示
VENV_DIR = '/home/rootuser/testvehic/vehic'
PROJECT_DIR = '/home/rootuser/testvehic/vehic/source/cabsdemo4'
@contextmanager
def source_virtualenv():
with prefix('source ' + os.path.join(VENV_DIR, 'bin/activate')):
yield
def test_deploy(gitid = '930bfc4'):
# manually put the commit id at the end
path = '/tmp/testapp/app1/source/demo4'
with cd(path):
commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
# change the settings.py file and update the database
run (commit_id)
run ('cat .git/FETCH_HEAD')
with settings(warn_only=True):
with cd(PROJECT_DIR):
with source_virtualenv():
run('pip install -r requirements.txt')
run('python manage.py test')
停止捆绑激活东西,太多人弄错了,改为这样做:
/tmp/testvehic/vehic/bin/python/tmp/testapp/app1/source/demo4/manage.py test
保证不会失败;没有人会看代码并被它弄糊涂;易于调试;只有胜利!!:P