2009-12-09 50 views
6

我試圖設置一個fabfile來部署我的Django應用程序。Fabric錯誤:致命錯誤:local()在執行'git commit -m'message'時遇到錯誤(返回碼2)

我想不通爲什麼我收到此錯誤:

Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'changed settings for prodserver'

$ fab create_branch_deploy_to_prodserver 
[localhost] run: git checkout prodserver_server 
[localhost] run: git merge master 
[localhost] run: cp settings_prodserver.py settings.py 
[localhost] run: git add settings.py 
[localhost] run: git commit -m 'changed settings for prodserver' 

Fatal error: local() encountered an error (return code 1) while executing 'git commit -m 'changed settings for prodserver'' 

Aborting. 

這裏,如果面料功能:

def create_branch_deploy_to_prodserver(): 
    local("git checkout prodserver_server") 
    local("git merge master") 
    local('cp settings_prodserver.py settings.py') # 
    #local('git rm fabfile.py') #This is also creating error so it's commented out 
    local('git add settings.py') 
    local("git commit -m 'changed settings for prodserver'") 

是否有可能做一個git從提交布?

回答

6

我能診斷問題,當我加入捕獲=假的聲明:

local('git rm fabfile.py', capture=False) 
local('git add settings.py', capture=False) 

這允許顯示錯誤更詳細地說。

顯然,Fabric的維護者會將local的行爲恢復爲默認情況下不在1.0中捕獲。

1

這是一個像this thread中描述的python相關的問題嗎?

The main problem with this is that the stdout/stderr capturing is per-run/sudo invocation and not per-task.

It would be wonderful if you could explain me how I could collect outputand error by only modifying the file called fabfile_runner.py.
Idealy the fabric task itself could be unmodified, this would allow to upload the the factory the same file that you have tested manually.

Check out the Fabric source and look in the 'tests' folder, specifically tests/utils.py. It contains a single decorator, @mock_streams , which is capable of wrapping a function (any function in any Python code -- it's not Fabric specific, as I mentioned) and redirecting sys.stdout and/or sys.stderr for capture/examination.

It's designed for use around functions, being a decorator, so you could use it directly by modifying your fabfile_runner.py like so:

fabfile_runner.py

from StringIO import StringIO 
import sys 
from test_fabfile import hello_world 

def execute(task): 
    output = StringIO() 
    error = StringIO() 
    sys.stdout = output 
    sys.stderr = error 
    task() 
    sys.stdout = sys.__stdout__ 
    sys.stderr = sys.__stderr__ 
    return (output.getvalue(), error.getvalue()) 

output, error = execute(hello_world) 
print "output : %s" %output 
print "error : %s" %error 
相關問題