~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Martin Pool
  • Date: 2009-09-14 01:48:28 UTC
  • mfrom: (4685 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090914014828-ydr9rlkdfq2sv57z
Merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.lazy_import import lazy_import
28
28
lazy_import(globals(), """
29
29
from bzrlib import (
 
30
    debug,
30
31
    progress,
31
32
    osutils,
32
33
    symbol_versioning,
49
50
                 stderr=None):
50
51
        """Create a TextUIFactory.
51
52
 
52
 
        :param bar_type: The type of progress bar to create. It defaults to
53
 
                         letting the bzrlib.progress.ProgressBar factory auto
54
 
                         select.   Deprecated.
 
53
        :param bar_type: The type of progress bar to create.  Deprecated
 
54
            and ignored; a TextProgressView is always used.
55
55
        """
56
56
        super(TextUIFactory, self).__init__()
57
57
        # TODO: there's no good reason not to pass all three streams, maybe we
222
222
        self._last_task = None
223
223
        self._total_byte_count = 0
224
224
        self._bytes_since_update = 0
 
225
        self._fraction = 0
225
226
 
226
227
    def _show_line(self, s):
 
228
        # sys.stderr.write("progress %r\n" % s)
227
229
        n = self._width - 1
228
230
        self._term_file.write('\r%-*.*s\r' % (n, n, s))
229
231
 
245
247
            cols = 20
246
248
            if self._last_task is None:
247
249
                completion_fraction = 0
 
250
                self._fraction = 0
248
251
            else:
249
252
                completion_fraction = \
250
253
                    self._last_task._overall_completion_fraction() or 0
 
254
            if (completion_fraction < self._fraction and 'progress' in
 
255
                debug.debug_flags):
 
256
                import pdb;pdb.set_trace()
 
257
            self._fraction = completion_fraction
251
258
            markers = int(round(float(cols) * completion_fraction)) - 1
252
259
            bar_str = '[' + ('#' * markers + spin_str).ljust(cols) + '] '
253
260
            return bar_str
283
290
            task_msg = self._format_task(self._last_task)
284
291
        else:
285
292
            task_msg = ''
286
 
        trans = self._last_transport_msg
287
 
        if trans:
288
 
            trans += ' | '
 
293
        if self._last_task and not self._last_task.show_transport_activity:
 
294
            trans = ''
 
295
        else:
 
296
            trans = self._last_transport_msg
 
297
            if trans:
 
298
                trans += ' | '
289
299
        return (bar_string + trans + task_msg)
290
300
 
291
301
    def _repaint(self):
302
312
        must_update = task is not self._last_task
303
313
        self._last_task = task
304
314
        now = time.time()
305
 
        if (not must_update) and (now < self._last_repaint + 0.1):
 
315
        if (not must_update) and (now < self._last_repaint + task.update_latency):
306
316
            return
307
317
        if now > self._transport_update_time + 10:
308
318
            # no recent activity; expire it
330
340
        self._total_byte_count += byte_count
331
341
        self._bytes_since_update += byte_count
332
342
        now = time.time()
 
343
        if self._total_byte_count < 2000:
 
344
            # a little resistance at first, so it doesn't stay stuck at 0
 
345
            # while connecting...
 
346
            return
333
347
        if self._transport_update_time is None:
334
348
            self._transport_update_time = now
335
349
        elif now >= (self._transport_update_time + 0.5):