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)
103
139
class UIFactory(object):
104
140
"""UI abstraction.
118
154
"%(from_format)s to %(to_format)s.\n"
119
155
"This may take some time. Upgrade the repositories to the "
120
156
"same format for better performance."
158
recommend_upgrade=("%(current_format_name)s is deprecated "
159
"and a better format is available.\n"
160
"It is recommended that you upgrade by "
161
"running the command\n"
162
" bzr upgrade %(basedir)s"),
124
165
def __init__(self):
152
193
self._quiet = state
195
def confirm_action(self, prompt, confirmation_id, prompt_kwargs):
196
"""Seek user confirmation for an action.
198
If the UI is noninteractive, or the user does not want to be asked
199
about this action, True is returned, indicating bzr should just
202
The confirmation id allows the user to configure certain actions to
203
always be confirmed or always denied, and for UIs to specialize the
204
display of particular confirmations.
206
:param prompt: Suggested text to display to the user.
207
:param prompt_kwargs: A dictionary of arguments that can be
208
string-interpolated into the prompt.
209
:param confirmation_id: Unique string identifier for the confirmation.
211
return self.get_boolean(prompt % prompt_kwargs)
154
213
def get_password(self, prompt='', **kwargs):
155
214
"""Prompt the user for a password.
290
349
return NullProgressView()
292
def recommend_upgrade(self,
295
# XXX: this should perhaps be in the TextUIFactory and the default can do
298
# XXX: Change to show_user_warning - that will accomplish the previous
299
# xxx. -- mbp 2010-02-25
300
trace.warning("%s is deprecated "
301
"and a better format is available.\n"
302
"It is recommended that you upgrade by "
303
"running the command\n"
351
def recommend_upgrade(self, current_format_name, basedir):
352
"""Recommend the user upgrade a control directory.
354
:param current_format_name: Description of the current format
355
:param basedir: Location of the control dir
357
self.show_user_warning('recommend_upgrade',
358
current_format_name=current_format_name, basedir=basedir)
308
360
def report_transport_activity(self, transport, byte_count, direction):
309
361
"""Called by transports as they do IO.
377
429
"without an upgrade path.\n" % (inter.target._format,))
380
class SilentUIFactory(UIFactory):
432
class NoninteractiveUIFactory(UIFactory):
433
"""Base class for UIs with no user."""
435
def confirm_action(self, prompt, confirmation_id, prompt_kwargs):
439
return '%s()' % (self.__class__.__name__, )
442
class SilentUIFactory(NoninteractiveUIFactory):
381
443
"""A UI Factory which never prints anything.
383
445
This is the default UI, if another one is never registered by a program
418
480
def __repr__(self):
419
481
return "%s(%r)" % (self.__class__.__name__, self.responses)
483
def confirm_action(self, prompt, confirmation_id, args):
484
return self.get_boolean(prompt % args)
421
486
def get_boolean(self, prompt):
422
487
return self.responses.pop(0)