I am using the Python library, Fabric , to do some maintenance on the remote server. Fabric automatically prints all responses to remote and local commands, unless you complete the command in pairs using statements. So on the local machine
with settings(warn_only='true'): with hide('running', 'stdout', 'stderr', 'warnings'): output = local("uname -a", True)
or like this on a remote computer:
with settings(warn_only='true'): with hide('running', 'stdout', 'stderr', 'warnings'): output = run("uname -a")
I write a long and complex task and repeat the repetition of the two with statements over and over. I want to write a function called _mute () to prevent it from repeating. This will allow me to do something like this:
def _mute(fabric_cmd, args): with settings(warn_only='true'): with hide('running', 'stdout', 'stderr', 'warnings'): output = fabric_cmd(args) return output def some_remote_task():
I reviewed some solutions and know that "eval" can do this for me. But every page I read about eval suggests that this is almost always a bad idea due to security concerns. I looked at partial ones, but I could not figure out how to make an argument in my _mute function callable. I assume there is a higher level of Python concept here. What is the pythonic way to do this? Thank you for any direction you could provide.
source share