Improve interactive mode for DNS plugin

Interactive mode for commands manipulating with DNS records
(dnsrecord-add, dnsrecord-del) is not usable. This patch enhances
the server framework with new callback for interactive mode, which
can be used by commands to inject their own interactive handling.

The callback is then used to improve aforementioned commands'
interactive mode.

https://fedorahosted.org/freeipa/ticket/1018
This commit is contained in:
Martin Kosek
2011-05-26 09:55:53 +02:00
parent c0f155bbfe
commit 585083c1d7
3 changed files with 225 additions and 20 deletions

View File

@@ -527,6 +527,47 @@ class textui(backend.Backend):
return None
return self.decode(data)
def prompt_yesno(self, label, default=None):
"""
Prompt user for yes/no input. This method returns True/False according
to user response.
Parameter "default" should be True, False or None
If Default parameter is not None, user can enter an empty input instead
of Yes/No answer. Value passed to Default is returned in that case.
If Default parameter is None, user is asked for Yes/No answer until
a correct answer is provided. Answer is then returned.
In case of an error, a None value may returned
"""
default_prompt = None
if default is not None:
if default:
default_prompt = "Yes"
else:
default_prompt = "No"
if default_prompt:
prompt = u'%s Yes/No (default %s): ' % (label, default_prompt)
else:
prompt = u'%s Yes/No: ' % label
while True:
try:
data = raw_input(self.encode(prompt)).lower()
except EOFError:
return None
if data in (u'yes', u'y'):
return True
elif data in ( u'n', u'no'):
return False
elif default is not None and data == u'':
return default
def prompt_password(self, label):
"""
Prompt user for a password or read it in via stdin depending
@@ -1032,6 +1073,9 @@ class cli(backend.Executioner):
param.label
)
for callback in getattr(cmd, 'INTERACTIVE_PROMPT_CALLBACKS', []):
callback(kw)
def load_files(self, cmd, kw):
"""
Load files from File parameters.