I try to make Fabric func, which checks if Apache installed:
from fabric.api import *
def check_apache():
try:
result = local('httpd -v', capture=True)
except:
print "check_apache exception"
But if httpd is not installed I get:
$ fab check_apache
Fatal error: local() encountered an error (return code 127) while executing 'ahttpd -v'
Aborting.
check_apache exception
Done.
How can I get correct exception for Fabric local()
method? So I need to get exception and continue executing without any Fabric error messages:
$ fab check_apache开发者_StackOverflow社区
check_apache exception
Done.
You can set env.warn_only
to True
or use the setting context manager. See http://docs.fabfile.org/0.9.3/api/core/context_managers.html?highlight=warn#fabric.context_managers.settings
精彩评论