[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] Collecting output when using Fabric directly in python
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] Collecting output when using Fabric directly in python |
Date: |
Tue, 18 Aug 2009 11:04:30 -0400 |
On Sun, Aug 16, 2009 at 1:57 PM, Steve
Steiner<address@hidden> wrote:
> Can this be done more nicely as a decorator since we've already got a Python
> 2.5+ requirement anyway?
>
> @capture_stderr
> def func_that_wants_stderr(...)
> pass
The main problem with this is that the stdout/stderr capturing is
per-run/sudo invocation and not per-task, so that doesn't mesh with
how I currently organize or think about things.
That said, it did make me realize that there *might* be a use case for
making the settings() context manager (and/or others) into a decorator
in some fashion. In other words, if one currently needed to write
this:
def myfunc():
with settings(warn_only=True):
# stuff
one could write the below modification, which would save a level of
indentation if you always need the entirety of the task "wrapped" in a
given settings change:
@settings(warn_only=True)
def myfunc():
# stuff
So if we were to create a global setting for what run/sudo/local
capture, one could then do basically what you describe:
@settings(capture_stderr=True)
def myfunc():
this_would_be_stderr = run('foo')
This is all just off the top of my head, still settling in after a
morning of traveling =)
Best,
Jeff