baobee
baobee

Reputation: 451

Fabric methods exceptions

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
check_apache exception

Done.

Upvotes: 2

Views: 1833

Answers (1)

Miki Tebeka
Miki Tebeka

Reputation: 13850

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

Upvotes: 1

Related Questions