103
class ConfirmationUserInterfacePolicy(object):
104
"""Wrapper for a UIFactory that allows or denies all confirmed actions."""
106
def __init__(self, wrapped_ui, default_answer, specific_answers):
107
"""Generate a proxy UI that does no confirmations.
109
:param wrapped_ui: Underlying UIFactory.
110
:param default_answer: Bool for whether requests for
111
confirmation from the user should be noninteractively accepted or
113
:param specific_answers: Map from confirmation_id to bool answer.
115
self.wrapped_ui = wrapped_ui
116
self.default_answer = default_answer
117
self.specific_answers = specific_answers
119
def __getattr__(self, name):
120
return getattr(self.wrapped_ui, name)
123
return '%s(%r, %r, %r)' % (
124
self.__class__.__name__,
127
self.specific_answers)
129
def confirm_action(self, prompt, confirmation_id, prompt_kwargs):
130
if confirmation_id in self.specific_answers:
131
return self.specific_answers[confirmation_id]
132
elif self.default_answer is not None:
133
return self.default_answer
135
return self.wrapped_ui.confirm_action(
136
prompt, confirmation_id, prompt_kwargs)
139
103
class UIFactory(object):
140
104
"""UI abstraction.
437
401
def confirm_action(self, prompt, confirmation_id, prompt_kwargs):
441
return '%s()' % (self.__class__.__name__, )
444
405
class SilentUIFactory(NoninteractiveUIFactory):
445
406
"""A UI Factory which never prints anything.
482
443
def __repr__(self):
483
444
return "%s(%r)" % (self.__class__.__name__, self.responses)
485
def confirm_action(self, prompt, confirmation_id, args):
446
def confirm_action(self, prompt, confirmation_id, args, default=True):
486
447
return self.get_boolean(prompt % args)
488
449
def get_boolean(self, prompt):