~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Parth Malwankar
  • Date: 2010-05-05 14:02:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5213.
  • Revision ID: parth.malwankar@gmail.com-20100505140253-fqdiwllq4o4htbsg
added comment to init/init-repo pass tests for lacking whoami.

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
30
34
from bzrlib.symbol_versioning import (
 
35
    deprecated_function,
31
36
    deprecated_in,
32
37
    deprecated_method,
33
38
    )
152
157
                own_fraction = 0.0
153
158
            return self._parent_task._overall_completion_fraction(own_fraction)
154
159
 
 
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
 
155
173
    def clear(self):
156
174
        # TODO: deprecate this method; the model object shouldn't be concerned
157
175
        # with whether it's shown or not.  Most callers use this because they
166
184
            self.ui_factory.clear_term()
167
185
 
168
186
 
 
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
 
169
235
class DummyProgress(object):
170
236
    """Progress-bar standin that does nothing.
171
237
 
187
253
    def clear(self):
188
254
        pass
189
255
 
 
256
    def note(self, fmt_string, *args, **kwargs):
 
257
        """See _BaseProgressBar.note()."""
 
258
 
190
259
    def child_progress(self, **kwargs):
191
260
        return DummyProgress(**kwargs)
192
261