~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: IWATA Hidetaka
  • Date: 2010-12-26 13:19:11 UTC
  • mto: This revision was merged to the branch mainline in revision 5593.
  • Revision ID: iwata0303@gmail.com-20101226131911-o7txs0fnji5zekq1
add icon resources tbzrcommand(w)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import os
28
28
 
29
29
 
30
 
from bzrlib import (
31
 
    errors,
32
 
    )
33
 
from bzrlib.trace import mutter
34
30
from bzrlib.symbol_versioning import (
35
 
    deprecated_function,
36
31
    deprecated_in,
37
32
    deprecated_method,
38
33
    )
157
152
                own_fraction = 0.0
158
153
            return self._parent_task._overall_completion_fraction(own_fraction)
159
154
 
160
 
    @deprecated_method(deprecated_in((2, 1, 0)))
161
 
    def note(self, fmt_string, *args):
162
 
        """Record a note without disrupting the progress bar.
163
 
        
164
 
        Deprecated: use ui_factory.note() instead or bzrlib.trace.  Note that
165
 
        ui_factory.note takes just one string as the argument, not a format
166
 
        string and arguments.
167
 
        """
168
 
        if args:
169
 
            self.ui_factory.note(fmt_string % args)
170
 
        else:
171
 
            self.ui_factory.note(fmt_string)
172
 
 
173
155
    def clear(self):
174
156
        # TODO: deprecate this method; the model object shouldn't be concerned
175
157
        # with whether it's shown or not.  Most callers use this because they
184
166
            self.ui_factory.clear_term()
185
167
 
186
168
 
187
 
# NOTE: This is also deprecated; you should provide a ProgressView instead.
188
 
class _BaseProgressBar(object):
189
 
 
190
 
    def __init__(self,
191
 
                 to_file=None,
192
 
                 show_pct=False,
193
 
                 show_spinner=False,
194
 
                 show_eta=False,
195
 
                 show_bar=True,
196
 
                 show_count=True,
197
 
                 to_messages_file=None,
198
 
                 _stack=None):
199
 
        object.__init__(self)
200
 
        if to_file is None:
201
 
            to_file = sys.stderr
202
 
        if to_messages_file is None:
203
 
            to_messages_file = sys.stdout
204
 
        self.to_file = to_file
205
 
        self.to_messages_file = to_messages_file
206
 
        self.last_msg = None
207
 
        self.last_cnt = None
208
 
        self.last_total = None
209
 
        self.show_pct = show_pct
210
 
        self.show_spinner = show_spinner
211
 
        self.show_eta = show_eta
212
 
        self.show_bar = show_bar
213
 
        self.show_count = show_count
214
 
        self._stack = _stack
215
 
        # seed throttler
216
 
        self.MIN_PAUSE = 0.1 # seconds
217
 
        now = time.time()
218
 
        # starting now
219
 
        self.start_time = now
220
 
        # next update should not throttle
221
 
        self.last_update = now - self.MIN_PAUSE - 1
222
 
 
223
 
    def finished(self):
224
 
        """Return this bar to its progress stack."""
225
 
        self.clear()
226
 
        self._stack.return_pb(self)
227
 
 
228
 
    def note(self, fmt_string, *args, **kwargs):
229
 
        """Record a note without disrupting the progress bar."""
230
 
        self.clear()
231
 
        self.to_messages_file.write(fmt_string % args)
232
 
        self.to_messages_file.write('\n')
233
 
 
234
 
 
235
169
class DummyProgress(object):
236
170
    """Progress-bar standin that does nothing.
237
171
 
253
187
    def clear(self):
254
188
        pass
255
189
 
256
 
    def note(self, fmt_string, *args, **kwargs):
257
 
        """See _BaseProgressBar.note()."""
258
 
 
259
190
    def child_progress(self, **kwargs):
260
191
        return DummyProgress(**kwargs)
261
192