~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    )
37
37
from bzrlib.trace import mutter
38
38
from bzrlib.symbol_versioning import (
 
39
    deprecated_function,
39
40
    deprecated_in,
40
41
    deprecated_method,
41
42
    )
42
43
 
43
44
 
 
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.
46
48
 
140
142
        self.ui_factory.clear_term()
141
143
 
142
144
 
 
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)
164
167
 
165
168
 
166
 
class ProgressBarStack(object):
167
 
    """A stack of progress bars.
168
 
 
169
 
    This class is deprecated: instead, ask the ui factory for a new progress
170
 
    task and finish it when it's done.
171
 
    """
172
 
 
173
 
    @deprecated_method(deprecated_in((1, 12, 0)))
174
 
    def __init__(self,
175
 
                 to_file=None,
176
 
                 show_pct=False,
177
 
                 show_spinner=True,
178
 
                 show_eta=False,
179
 
                 show_bar=True,
180
 
                 show_count=True,
181
 
                 to_messages_file=None,
182
 
                 klass=None):
183
 
        """Setup the stack with the parameters the progress bars should have."""
184
 
        if to_file is None:
185
 
            to_file = sys.stderr
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
195
 
        self._stack = []
196
 
        self._klass = klass or ProgressBar
197
 
 
198
 
    def top(self):
199
 
        if len(self._stack) != 0:
200
 
            return self._stack[-1]
201
 
        else:
202
 
            return None
203
 
 
204
 
    def bottom(self):
205
 
        if len(self._stack) != 0:
206
 
            return self._stack[0]
207
 
        else:
208
 
            return None
209
 
 
210
 
    def get_nested(self):
211
 
        """Return a nested progress bar."""
212
 
        if len(self._stack) == 0:
213
 
            func = self._klass
214
 
        else:
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,
223
 
                       _stack=self)
224
 
        self._stack.append(new_bar)
225
 
        return new_bar
226
 
 
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,))
231
 
        else:
232
 
            self._stack.pop()
233
 
 
234
 
 
235
169
class _BaseProgressBar(object):
236
170
 
237
171
    def __init__(self,
278
212
        self.to_messages_file.write(fmt_string % args)
279
213
        self.to_messages_file.write('\n')
280
214
 
 
215
    @deprecated_function(deprecated_in((1, 16, 0)))
281
216
    def child_progress(self, **kwargs):
282
217
        return ChildProgress(**kwargs)
283
218
 
309
244
 
310
245
class DotsProgressBar(_BaseProgressBar):
311
246
 
 
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
335
271
        self.tick()
336
272
 
337
273
 
338
 
 
339
 
 
340
274
class TTYProgressBar(_BaseProgressBar):
341
275
    """Progress bar display object.
342
276
 
359
293
    """
360
294
    SPIN_CHARS = r'/-\|'
361
295
 
362
 
 
 
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()
520
454
 
521
455
 
522
 
 
523
 
 
524
456
class ChildProgress(_BaseProgressBar):
525
457
    """A progress indicator that pushes its data to the parent"""
526
458
 
 
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)
566
499
 
567
500
 
568
 
class InstrumentedProgress(TTYProgressBar):
569
 
    """TTYProgress variant that tracks outcomes"""
570
 
 
571
 
    def __init__(self, *args, **kwargs):
572
 
        self.always_throttled = True
573
 
        self.never_throttle = False
574
 
        TTYProgressBar.__init__(self, *args, **kwargs)
575
 
 
576
 
    def throttle(self, old_message):
577
 
        if self.never_throttle:
578
 
            result =  False
579
 
        else:
580
 
            result = TTYProgressBar.throttle(self, old_message)
581
 
        if result is False:
582
 
            self.always_throttled = False
583
 
 
584
 
 
585
501
def str_tdelta(delt):
586
502
    if delt is None:
587
503
        return "-:--:--"