Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Fabric: How to answer to keyboard input?

Tags:

I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.

For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet' like option. But how can I pass the response to other programs ?

like image 631
dzen Avatar asked Feb 11 '10 17:02

dzen


People also ask

How do you accept keyboard input in python?

Use the input() function to get Python user input from keyboard. Press the enter key after entering the value. The program waits for user input indefinetly, there is no timeout.

Which Python method reads a string of text from the keyboard?

raw_input() in Python 2 reads input from the keyboard and returns it.


1 Answers

If you are looking for a user to confirm an operation, use the confrim method.

if fabric.contrib.console.confirm("You tests failed do you want to continue?"):   #continue processing 

Or if you are looking for a way to get input from the user, use the prompt method.

password = fabric.operations.prompt("What is your password?") 
like image 145
buckley Avatar answered Dec 21 '22 09:12

buckley