Jeff Forcier wrote:

> On Thu, Oct 20, 2011 at 2:06 PM, John Eikenberry <[email protected]> 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
[ [email protected] - 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

_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to