31
30
from bzrlib import (
37
33
from bzrlib.trace import mutter
38
34
from bzrlib.symbol_versioning import (
40
# XXX: deprecated; can be removed when the ProgressBar factory is removed
44
41
def _supports_progress(f):
45
42
"""Detect if we can use pretty progress bars on the output stream f.
140
137
self.ui_factory.clear_term()
140
@deprecated_function(deprecated_in((1, 16, 0)))
143
141
def ProgressBar(to_file=None, **kwargs):
144
142
"""Abstract factory"""
145
143
if to_file is None:
163
161
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
164
class _BaseProgressBar(object):
237
166
def __init__(self,
278
207
self.to_messages_file.write(fmt_string % args)
279
208
self.to_messages_file.write('\n')
210
@deprecated_function(deprecated_in((1, 16, 0)))
281
211
def child_progress(self, **kwargs):
282
212
return ChildProgress(**kwargs)
310
240
class DotsProgressBar(_BaseProgressBar):
242
@deprecated_function(deprecated_in((1, 16, 0)))
312
243
def __init__(self, **kwargs):
313
244
_BaseProgressBar.__init__(self, **kwargs)
314
245
self.last_msg = None
360
289
SPIN_CHARS = r'/-\|'
291
@deprecated_function(deprecated_in((1, 16, 0)))
363
292
def __init__(self, **kwargs):
364
293
from bzrlib.osutils import terminal_width
365
294
_BaseProgressBar.__init__(self, **kwargs)
519
448
#self.to_file.flush()
524
451
class ChildProgress(_BaseProgressBar):
525
452
"""A progress indicator that pushes its data to the parent"""
454
@deprecated_function(deprecated_in((1, 16, 0)))
527
455
def __init__(self, _stack, **kwargs):
528
456
_BaseProgressBar.__init__(self, _stack=_stack, **kwargs)
529
457
self.parent = _stack.top()
565
493
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
496
def str_tdelta(delt):