fabric/fabric — pull request #741 by owenn (2012-09-27 11:12:50+00:00)
Title: Allows the creation of custom prompts and responses to allow custom prompts for contextmanagers.

Allows the creation of custom prompts and responses. I wrote it to allow custom contextmanagers as in the following example:

from fabric.api import env, run
import contextlib

@contextlib.contextmanager
def asu(user, asu_number):
'"""custom ASU wrapper around sudo"""

save_shell = env.shell

save_current_prompts = env.request_prompts
env.request_prompts = { "Enter ASU #:" : asu_number, "Password:" : "testpassword" }

env.shell = '$HOME/asu %s -c' % user
yield
env.shell = save_shell
env.request_prompts = save_current_prompts

And in the fab file:

with asu("root",asu_number):
run("touch /var/tmp/test.touch")