Commit 289fb633 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis

utils: Fix ask_user prompt

In case no input is given and the user just presses enter,
raw_input() will return an empty string ('') and thus, if we refer
to the first character of the response, an IndexError will be
raised.

Fix this.
Signed-off-by: default avatarDimitris Aragiorgis <dimitris.aragiorgis@gmail.com>
parent 67868d4f
......@@ -387,8 +387,10 @@ def ask_user(msg, true_resp=('y', ), **kwargs):
msg = escape_ctrl_chars(msg).encode(pref_enc, 'replace')
yep = yep.encode(pref_enc, 'replace')
nope = nope.encode(pref_enc, 'replace')
user_response = raw_input(
response = raw_input(
'%s [%s/%s]: ' % (msg, yep, nope))
# Pressing just enter gives an empty response!
user_response = response if response else 'N'
return user_response[0].lower() in [s.lower() for s in true_resp]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment