~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

Got stack handling under test

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
        self._stack = []
90
90
        self._klass = klass or TTYProgressBar
91
91
 
 
92
    def top(self):
 
93
        if len(self._stack) != 0:
 
94
            return self._stack[-1]
 
95
        else:
 
96
            return None
 
97
 
92
98
    def get_nested(self):
93
99
        """Return a nested progress bar."""
94
 
        # initial implementation - return a new bar each time.
95
 
        new_bar = self._klass(to_file=self._to_file,
96
 
                              show_pct=self._show_pct,
97
 
                              show_spinner=self._show_spinner,
98
 
                              show_eta=self._show_eta,
99
 
                              show_bar=self._show_bar,
100
 
                              show_count=self._show_count,
101
 
                              to_messages_file=self._to_messages_file,
102
 
                              _stack=self)
 
100
        if len(self._stack) == 0:
 
101
            func = self._klass
 
102
        else:
 
103
            func = self.top().child_progress
 
104
        new_bar = func(to_file=self._to_file,
 
105
                       show_pct=self._show_pct,
 
106
                       show_spinner=self._show_spinner,
 
107
                       show_eta=self._show_eta,
 
108
                       show_bar=self._show_bar,
 
109
                       show_count=self._show_count,
 
110
                       to_messages_file=self._to_messages_file,
 
111
                       _stack=self)
103
112
        self._stack.append(new_bar)
104
113
        return new_bar
105
114
 
146
155
        self.to_messages_file.write(fmt_string % args)
147
156
        self.to_messages_file.write('\n')
148
157
 
 
158
    def child_progress(self, **kwargs):
 
159
        return ChildProgress(**kwargs)
 
160
 
149
161
 
150
162
class DummyProgress(_BaseProgressBar):
151
163
    """Progress-bar standin that does nothing.
167
179
    def note(self, fmt_string, *args, **kwargs):
168
180
        """See _BaseProgressBar.note()."""
169
181
 
 
182
    def child_progress(self, **kwargs):
 
183
        return DummyProgress(**kwargs)
170
184
 
171
185
class DotsProgressBar(_BaseProgressBar):
172
186
 
348
362
 
349
363
class ChildProgress(_BaseProgressBar):
350
364
    """A progress indicator that pushes its data to the parent"""
351
 
    def __init__(self, stack, **kwargs):
352
 
        super(_BaseProgressBar, self).__init__(stack=stack, **kwargs)
353
 
        self.parent = stack[-1]
 
365
    def __init__(self, _stack, **kwargs):
 
366
        _BaseProgressBar.__init__(self, _stack=_stack, **kwargs)
 
367
        self.parent = _stack.top()
354
368
        self.current = None
355
369
        self.total = None
356
370
        self.child_fraction = 0
374
388
            count = self.total
375
389
        self.parent.child_update(self.message, count, self.total)
376
390
 
 
391
    def clear(self):
 
392
        self.parent.clear()
 
393
 
377
394
 
378
395
def str_tdelta(delt):
379
396
    if delt is None: