~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-18 17:58:10 UTC
  • mto: This revision was merged to the branch mainline in revision 4934.
  • Revision ID: john@arbash-meinel.com-20091218175810-07kjs6e20i30acob
Include the KiB/s for the transfer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
265
265
        self._total_byte_count = 0
266
266
        self._bytes_since_update = 0
267
267
        self._bytes_by_direction = {'unknown': 0, 'read': 0, 'write': 0}
 
268
        self._first_byte_time = None
268
269
        self._fraction = 0
269
270
        # force the progress bar to be off, as at the moment it doesn't 
270
271
        # correspond reliably to overall command progress
382
383
        # here.
383
384
        self._total_byte_count += byte_count
384
385
        self._bytes_since_update += byte_count
 
386
        if self._first_byte_time is None:
 
387
            # Note that this isn't great, as technically it should be the time
 
388
            # when the bytes started transferring, not when they completed.
 
389
            # However, we usually start with a small request anyway.
 
390
            self._first_byte_time = time.time()
385
391
        if direction in self._bytes_by_direction:
386
392
            self._bytes_by_direction[direction] += byte_count
387
393
        else:
414
420
            self._repaint()
415
421
 
416
422
    def _format_bytes_by_direction(self):
 
423
        if self._first_byte_time is None:
 
424
            bps = 0.0
 
425
        else:
 
426
            transfer_time = time.time() - self._first_byte_time
 
427
            if transfer_time < 0.001:
 
428
                transfer_time = 0.001
 
429
            bps = self._total_byte_count / transfer_time
 
430
 
417
431
        msg = ('Transferred: %.3fMiB'
418
 
               ' (r:%.3fMiB w:%.3fMiB'
 
432
               ' (%.1fKiB/s r:%.3fMiB w:%.3fMiB'
419
433
               % (self._total_byte_count / 1024. / 1024.,
 
434
                  bps / 1024.,
420
435
                  self._bytes_by_direction['read'] / 1024. / 1024.,
421
436
                  self._bytes_by_direction['write'] / 1024. / 1024.,
422
437
                 ))