~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Martin Pool
  • Date: 2010-01-12 01:44:13 UTC
  • mto: (4634.119.3 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: mbp@sourcefrog.net-20100112014413-uw90vrssc3trlzmt
Refuse to build with pyrex 0.9.4*

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Text UI, write output to the console.
19
19
"""
20
20
 
 
21
import getpass
21
22
import os
22
23
import sys
23
24
import time
26
27
from bzrlib.lazy_import import lazy_import
27
28
lazy_import(globals(), """
28
29
from bzrlib import (
 
30
    debug,
29
31
    progress,
30
32
    osutils,
31
33
    symbol_versioning,
48
50
                 stderr=None):
49
51
        """Create a TextUIFactory.
50
52
 
51
 
        :param bar_type: The type of progress bar to create. It defaults to
52
 
                         letting the bzrlib.progress.ProgressBar factory auto
53
 
                         select.   Deprecated.
 
53
        :param bar_type: The type of progress bar to create.  Deprecated
 
54
            and ignored; a TextProgressView is always used.
54
55
        """
55
56
        super(TextUIFactory, self).__init__()
56
57
        # TODO: there's no good reason not to pass all three streams, maybe we
221
222
        self._last_task = None
222
223
        self._total_byte_count = 0
223
224
        self._bytes_since_update = 0
 
225
        self._fraction = 0
224
226
 
225
227
    def _show_line(self, s):
 
228
        # sys.stderr.write("progress %r\n" % s)
226
229
        n = self._width - 1
227
230
        self._term_file.write('\r%-*.*s\r' % (n, n, s))
228
231
 
244
247
            cols = 20
245
248
            if self._last_task is None:
246
249
                completion_fraction = 0
 
250
                self._fraction = 0
247
251
            else:
248
252
                completion_fraction = \
249
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
250
258
            markers = int(round(float(cols) * completion_fraction)) - 1
251
259
            bar_str = '[' + ('#' * markers + spin_str).ljust(cols) + '] '
252
260
            return bar_str
282
290
            task_msg = self._format_task(self._last_task)
283
291
        else:
284
292
            task_msg = ''
285
 
        trans = self._last_transport_msg
286
 
        if trans:
287
 
            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 += ' | '
288
299
        return (bar_string + trans + task_msg)
289
300
 
290
301
    def _repaint(self):
301
312
        must_update = task is not self._last_task
302
313
        self._last_task = task
303
314
        now = time.time()
304
 
        if (not must_update) and (now < self._last_repaint + 0.1):
 
315
        if (not must_update) and (now < self._last_repaint + task.update_latency):
305
316
            return
306
317
        if now > self._transport_update_time + 10:
307
318
            # no recent activity; expire it
329
340
        self._total_byte_count += byte_count
330
341
        self._bytes_since_update += byte_count
331
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
332
347
        if self._transport_update_time is None:
333
348
            self._transport_update_time = now
334
349
        elif now >= (self._transport_update_time + 0.5):