/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-08 14:37:25 UTC
  • mfrom: (4516 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4517.
  • Revision ID: john@arbash-meinel.com-20090708143725-sc9sjy3mz4cxwxzz
Merge bzr.dev 4516

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import sys
26
26
import time
27
27
import os
28
 
import warnings
29
28
 
30
29
 
31
30
from bzrlib import (
32
31
    errors,
33
 
    osutils,
34
 
    trace,
35
 
    ui,
36
32
    )
37
33
from bzrlib.trace import mutter
38
34
from bzrlib.symbol_versioning import (
 
35
    deprecated_function,
39
36
    deprecated_in,
40
 
    deprecated_method,
41
37
    )
42
38
 
43
39
 
 
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.
46
43
 
140
137
        self.ui_factory.clear_term()
141
138
 
142
139
 
 
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)
164
162
 
165
163
 
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
164
class _BaseProgressBar(object):
236
165
 
237
166
    def __init__(self,
278
207
        self.to_messages_file.write(fmt_string % args)
279
208
        self.to_messages_file.write('\n')
280
209
 
 
210
    @deprecated_function(deprecated_in((1, 16, 0)))
281
211
    def child_progress(self, **kwargs):
282
212
        return ChildProgress(**kwargs)
283
213
 
309
239
 
310
240
class DotsProgressBar(_BaseProgressBar):
311
241
 
 
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
335
266
        self.tick()
336
267
 
337
268
 
338
 
 
339
 
 
340
269
class TTYProgressBar(_BaseProgressBar):
341
270
    """Progress bar display object.
342
271
 
359
288
    """
360
289
    SPIN_CHARS = r'/-\|'
361
290
 
362
 
 
 
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()
520
449
 
521
450
 
522
 
 
523
 
 
524
451
class ChildProgress(_BaseProgressBar):
525
452
    """A progress indicator that pushes its data to the parent"""
526
453
 
 
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)
566
494
 
567
495
 
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
496
def str_tdelta(delt):
586
497
    if delt is None:
587
498
        return "-:--:--"