2
的一系列標準的面料例子失敗了,我們有的Python面料:在命令
def test():
with settings(warn_only=True):
result = local('./manage.py test my_app', capture=True)
if result.failed and not confirm("Tests failed. Continue anyway?"):
abort("Aborting at user request.")
有沒有什麼辦法來檢查整個方法的狀態?
例如,
def method1():
run_this_as_sudo
run_this_as_sudo
我如何檢查,看看整個方法織物失敗,而不是看着每個人的方法調用?處理這個問題的唯一方法是在每個由多個shell命令組成的方法上添加某種try catch。在有條件的
╭─[email protected] ~
╰─$ fab -f tmp.py test
Ok
Something failed
Done.
╭─[email protected] ~
╰─$ cat tmp.py
from fabric.api import local, task, quiet
@task
def test():
with quiet():
if local("whoami").succeeded and local("echo good").succeeded:
print "Ok"
else:
print "Something failed"
if local("exit 1").succeeded and local("echo good").succeeded:
print "Ok"
else:
print "Something failed"
我只是鏈接調用在一起,並使用他們返回,使有條件的撥動布爾變量:
您可能會爲此捕獲一個'SystemExit'異常。參見:http://stackoverflow.com/questions/5481742/how-to-catch-auth-errors-in-fabric-and-retry – Roshambo