开发者

Fabric methods exceptions

开发者 https://www.devze.com 2023-02-11 22:18 出处:网络
I try to make Fabric func, which checks if Apache installed: from fabric.api import * def check_apache():

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

0

精彩评论

暂无评论...
验证码 换一张
取 消