203
204
self._progress_view.show_transport_activity(transport,
204
205
direction, byte_count)
207
def log_transport_activity(self, display=False):
208
"""See UIFactory.log_transport_activity()"""
209
log = getattr(self._progress_view, 'log_transport_activity', None)
206
213
def show_error(self, msg):
207
214
self.clear_term()
208
215
self.stderr.write("bzr: error: %s\n" % msg)
257
264
self._last_task = None
258
265
self._total_byte_count = 0
259
266
self._bytes_since_update = 0
267
self._bytes_by_direction = {'unknown': 0, 'read': 0, 'write': 0}
268
self._first_byte_time = None
260
269
self._fraction = 0
261
270
# force the progress bar to be off, as at the moment it doesn't
262
271
# correspond reliably to overall command progress
369
378
This may update a progress bar, spinner, or similar display.
370
379
By default it does nothing.
372
# XXX: Probably there should be a transport activity model, and that
373
# too should be seen by the progress view, rather than being poked in
381
# XXX: there should be a transport activity model, and that too should
382
# be seen by the progress view, rather than being poked in here.
383
self._total_byte_count += byte_count
384
self._bytes_since_update += byte_count
385
if self._first_byte_time is None:
386
# Note that this isn't great, as technically it should be the time
387
# when the bytes started transferring, not when they completed.
388
# However, we usually start with a small request anyway.
389
self._first_byte_time = time.time()
390
if direction in self._bytes_by_direction:
391
self._bytes_by_direction[direction] += byte_count
393
self._bytes_by_direction['unknown'] += byte_count
375
394
if 'no_activity' in debug.debug_flags:
376
395
# Can be used as a workaround if
377
396
# <https://launchpad.net/bugs/321935> reappears and transport
378
397
# activity is cluttering other output. However, thanks to
379
398
# TextUIOutputStream this shouldn't be a problem any more.
381
self._total_byte_count += byte_count
382
self._bytes_since_update += byte_count
383
400
now = time.time()
384
401
if self._total_byte_count < 2000:
385
402
# a little resistance at first, so it doesn't stay stuck at 0
399
416
self._last_transport_msg = msg
419
def _format_bytes_by_direction(self):
420
if self._first_byte_time is None:
423
transfer_time = time.time() - self._first_byte_time
424
if transfer_time < 0.001:
425
transfer_time = 0.001
426
bps = self._total_byte_count / transfer_time
428
msg = ('Transferred: %.0fKiB'
429
' (%.1fK/s r:%.0fK w:%.0fK'
430
% (self._total_byte_count / 1024.,
432
self._bytes_by_direction['read'] / 1024.,
433
self._bytes_by_direction['write'] / 1024.,
435
if self._bytes_by_direction['unknown'] > 0:
436
msg += ' u:%.0fK)' % (
437
self._bytes_by_direction['unknown'] / 1024.
443
def log_transport_activity(self, display=False):
444
msg = self._format_bytes_by_direction()
446
if display and self._total_byte_count > 0:
448
self._term_file.write(msg + '\n')
403
451
class TextUIOutputStream(object):
404
452
"""Decorates an output stream so that the terminal is cleared before writing.