Errore tessuto:Errore fatale:local() ha riscontrato un errore (codice restituito 2) durante l'esecuzione di 'git commit -m 'message'
Domanda
Sto provando a configurare un fabfile per distribuire la mia app Django.
Non riesco a capire perché ricevo questo errore:
Errore fatale:local() ha riscontrato un errore (codice restituito 2) durante l'esecuzione di 'git commit -m 'impostazioni modificate per 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.
Qui se la funzione Tessuto:
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'")
È possibile effettuare un commit git da Fabric?
Soluzione
Sono stato in grado di diagnosticare il problema quando ho aggiunto la cattura = False alla dichiarazione:
local('git rm fabfile.py', capture=False)
local('git add settings.py', capture=False)
Questo ha permesso l'errore da visualizzare più verboso.
A quanto pare, il manutentore del tessuto sarà per ripristinare il comportamento di local
di nuovo a non catturare per impostazione predefinita, in 1.0.
Altri suggerimenti
Si tratta di un problema relativo a Python come quello descritto in questo filo?
Il problema principale con questo è che
stdout
/stderr
l'acquisizione avviene per esecuzione/invocazione sudo e non per attività.Sarebbe meraviglioso se potessi spiegarmi come posso collezionare produzioneE errore modificando solo il file chiamato
fabfile_runner.py
.
Idealmente l'attività del tessuto stesso potrebbe non essere modificata, ciò consentirebbe di caricare in fabbrica lo stesso file che hai testato manualmente.Controlla il sorgente Fabric e cerca nella cartella 'tests', in particolare tests/utils.py.Contiene un singolo decoratore,
@mock_streams
, che è in grado di racchiudere una funzione (qualsiasi funzione in qualsiasi codice Python - non è specifica di Fabric, come ho detto) e reindirizzaresys.stdout
e/osys.stderr
per la cattura/esame.È progettato per l'uso con le funzioni, essendo un decoratore, quindi puoi usarlo direttamente modificando il tuo file
fabfile_runner.py
così:
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