On Tue, Aug 18, 2009 at 11:04 AM, Jeff Forcier
<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:
address@hidden(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:
address@hidden(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