fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] how to skip unreachable hosts


From: John Eikenberry
Subject: Re: [Fab-user] how to skip unreachable hosts
Date: Mon, 24 Oct 2011 11:01:10 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

Jeff Forcier wrote:

> On Thu, Oct 20, 2011 at 2:06 PM, John Eikenberry <address@hidden> wrote:
> 
> > Opps. Forgot to clean out that _quiet(). It just wraps the command in some
> > contexts to shut up various output.
> 
> Just curious -- how does _quiet() differ from using the hide/show
> context managers? Output management has always been relatively naive
> and at some point I'm hoping to make it more powerful/flexible, if
> possible.

_quiet() is really just a lighter weight way to wrap a function in a context
without the 'with' block. Something I could easily wrap around an existing
function. Nothing special.

Here is the implementation in case you're curious.

def _quiet(fun):
    """ Ignore errors and just return result.
    """
    return _contextualize(fun,
            fab.settings(fab.hide('everything'), warn_only=True))

def _contextualize(fun, cm):
    """ Wraps function (fun) in contextmanager (cm).
    """
    @functools.wraps(fun)
    def newfun(*a, **kw):
        with cm:
            return fun(*a, **kw)
    return newfun


-- 

John Eikenberry
[ address@hidden - http://zhar.net ]
[ PGP public key @ http://zhar.net/jae_at_zhar_net.gpg ]
________________________________________________________________________
"Perfection is attained, not when no more can be added, but when no more
 can be removed." -- Antoine de Saint-Exupery

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]