37
37
from bzrlib.trace import mutter
38
38
from bzrlib.symbol_versioning import (
45
# XXX: deprecated; can be removed when the ProgressBar factory is removed
44
46
def _supports_progress(f):
45
47
"""Detect if we can use pretty progress bars on the output stream f.
140
142
self.ui_factory.clear_term()
145
@deprecated_function(deprecated_in((1, 16, 0)))
143
146
def ProgressBar(to_file=None, **kwargs):
144
147
"""Abstract factory"""
145
148
if to_file is None:
163
166
return _progress_bar_types[requested_bar_type](to_file=to_file, **kwargs)
166
class ProgressBarStack(object):
167
"""A stack of progress bars.
169
This class is deprecated: instead, ask the ui factory for a new progress
170
task and finish it when it's done.
173
@deprecated_method(deprecated_in((1, 12, 0)))
181
to_messages_file=None,
183
"""Setup the stack with the parameters the progress bars should have."""
186
if to_messages_file is None:
187
to_messages_file = sys.stdout
188
self._to_file = to_file
189
self._show_pct = show_pct
190
self._show_spinner = show_spinner
191
self._show_eta = show_eta
192
self._show_bar = show_bar
193
self._show_count = show_count
194
self._to_messages_file = to_messages_file
196
self._klass = klass or ProgressBar
199
if len(self._stack) != 0:
200
return self._stack[-1]
205
if len(self._stack) != 0:
206
return self._stack[0]
210
def get_nested(self):
211
"""Return a nested progress bar."""
212
if len(self._stack) == 0:
215
func = self.top().child_progress
216
new_bar = func(to_file=self._to_file,
217
show_pct=self._show_pct,
218
show_spinner=self._show_spinner,
219
show_eta=self._show_eta,
220
show_bar=self._show_bar,
221
show_count=self._show_count,
222
to_messages_file=self._to_messages_file,
224
self._stack.append(new_bar)
227
def return_pb(self, bar):
228
"""Return bar after its been used."""
229
if bar is not self._stack[-1]:
230
warnings.warn("%r is not currently active" % (bar,))
235
169
class _BaseProgressBar(object):
237
171
def __init__(self,
278
212
self.to_messages_file.write(fmt_string % args)
279
213
self.to_messages_file.write('\n')
215
@deprecated_function(deprecated_in((1, 16, 0)))
281
216
def child_progress(self, **kwargs):
282
217
return ChildProgress(**kwargs)
310
245
class DotsProgressBar(_BaseProgressBar):
247
@deprecated_function(deprecated_in((1, 16, 0)))
312
248
def __init__(self, **kwargs):
313
249
_BaseProgressBar.__init__(self, **kwargs)
314
250
self.last_msg = None
360
294
SPIN_CHARS = r'/-\|'
296
@deprecated_function(deprecated_in((1, 16, 0)))
363
297
def __init__(self, **kwargs):
364
298
from bzrlib.osutils import terminal_width
365
299
_BaseProgressBar.__init__(self, **kwargs)
519
453
#self.to_file.flush()
524
456
class ChildProgress(_BaseProgressBar):
525
457
"""A progress indicator that pushes its data to the parent"""
459
@deprecated_function(deprecated_in((1, 16, 0)))
527
460
def __init__(self, _stack, **kwargs):
528
461
_BaseProgressBar.__init__(self, _stack=_stack, **kwargs)
529
462
self.parent = _stack.top()
565
498
self.parent.note(*args, **kwargs)
568
class InstrumentedProgress(TTYProgressBar):
569
"""TTYProgress variant that tracks outcomes"""
571
def __init__(self, *args, **kwargs):
572
self.always_throttled = True
573
self.never_throttle = False
574
TTYProgressBar.__init__(self, *args, **kwargs)
576
def throttle(self, old_message):
577
if self.never_throttle:
580
result = TTYProgressBar.throttle(self, old_message)
582
self.always_throttled = False
585
501
def str_tdelta(delt):