/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

remove all trailing whitespace from bzr source

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
def _supports_progress(f):
47
47
    """Detect if we can use pretty progress bars on the output stream f.
48
48
 
49
 
    If this returns true we expect that a human may be looking at that 
 
49
    If this returns true we expect that a human may be looking at that
50
50
    output, and that we can repaint a line to update it.
51
51
    """
52
52
    isatty = getattr(f, 'isatty', None)
63
63
class ProgressTask(object):
64
64
    """Model component of a progress indicator.
65
65
 
66
 
    Most code that needs to indicate progress should update one of these, 
 
66
    Most code that needs to indicate progress should update one of these,
67
67
    and it will in turn update the display, if one is present.
68
68
 
69
69
    Code updating the task may also set fields as hints about how to display
102
102
 
103
103
    def _overall_completion_fraction(self, child_fraction=0.0):
104
104
        """Return fractional completion of this task and its parents
105
 
        
 
105
 
106
106
        Returns None if no completion can be computed."""
107
107
        if self.total_cnt:
108
108
            own_fraction = (float(self.current_cnt) + child_fraction) / self.total_cnt
211
211
        else:
212
212
            self._stack.pop()
213
213
 
214
 
 
 
214
 
215
215
class _BaseProgressBar(object):
216
216
 
217
217
    def __init__(self,
279
279
 
280
280
    def clear(self):
281
281
        pass
282
 
        
 
282
 
283
283
    def note(self, fmt_string, *args, **kwargs):
284
284
        """See _BaseProgressBar.note()."""
285
285
 
293
293
        _BaseProgressBar.__init__(self, **kwargs)
294
294
        self.last_msg = None
295
295
        self.need_nl = False
296
 
        
 
296
 
297
297
    def tick(self):
298
298
        self.update()
299
 
        
 
299
 
300
300
    def update(self, msg=None, current_cnt=None, total_cnt=None):
301
301
        if msg and msg != self.last_msg:
302
302
            if self.need_nl:
305
305
            self.last_msg = msg
306
306
        self.need_nl = True
307
307
        self.to_file.write('.')
308
 
        
 
308
 
309
309
    def clear(self):
310
310
        if self.need_nl:
311
311
            self.to_file.write('\n')
312
312
        self.need_nl = False
313
 
        
 
313
 
314
314
    def child_update(self, message, current, total):
315
315
        self.tick()
316
316
 
317
317
 
318
318
 
319
 
    
 
319
 
320
320
class TTYProgressBar(_BaseProgressBar):
321
321
    """Progress bar display object.
322
322
 
349
349
        self._max_last_updates = 10
350
350
        self.child_fraction = 0
351
351
        self._have_output = False
352
 
    
 
352
 
353
353
    def throttle(self, old_msg):
354
354
        """Return True if the bar was updated too recently"""
355
355
        # time.time consistently takes 40/4000 ms = 0.01 ms.
369
369
        self.last_updates = self.last_updates[-self._max_last_updates:]
370
370
        self.last_update = now
371
371
        return False
372
 
        
 
372
 
373
373
    def tick(self):
374
374
        self.update(self.last_msg, self.last_cnt, self.last_total,
375
375
                    self.child_fraction)
397
397
 
398
398
        if current_cnt < 0:
399
399
            current_cnt = 0
400
 
            
 
400
 
401
401
        if current_cnt > total_cnt:
402
402
            total_cnt = current_cnt
403
 
        
404
 
        ## # optional corner case optimisation 
 
403
 
 
404
        ## # optional corner case optimisation
405
405
        ## # currently does not seem to fire so costs more than saved.
406
406
        ## # trivial optimal case:
407
407
        ## # NB if callers are doing a clear and restore with
424
424
        self.last_total = total_cnt
425
425
        self.child_fraction = child_fraction
426
426
 
427
 
        # each function call takes 20ms/4000 = 0.005 ms, 
 
427
        # each function call takes 20ms/4000 = 0.005 ms,
428
428
        # but multiple that by 4000 calls -> starts to cost.
429
429
        # so anything to make this function call faster
430
430
        # will improve base 'diff' time by up to 0.1 seconds.
432
432
            return
433
433
 
434
434
        if self.show_eta and self.start_time and self.last_total:
435
 
            eta = get_eta(self.start_time, self.last_cnt + self.child_fraction, 
 
435
            eta = get_eta(self.start_time, self.last_cnt + self.child_fraction,
436
436
                    self.last_total, last_updates = self.last_updates)
437
437
            eta_str = " " + str_tdelta(eta)
438
438
        else:
439
439
            eta_str = ""
440
440
 
441
441
        if self.show_spinner:
442
 
            spin_str = self.SPIN_CHARS[self.spin_pos % 4] + ' '            
 
442
            spin_str = self.SPIN_CHARS[self.spin_pos % 4] + ' '
443
443
        else:
444
444
            spin_str = ''
445
445
 
471
471
 
472
472
            if self.last_total:
473
473
                # number of markers highlighted in bar
474
 
                markers = int(round(float(cols) * 
 
474
                markers = int(round(float(cols) *
475
475
                              (self.last_cnt + self.child_fraction) / self.last_total))
476
476
                bar_str = '[' + ('=' * markers).ljust(cols) + '] '
477
477
            elif False:
479
479
                # so just show an expanded spinning thingy
480
480
                m = self.spin_pos % cols
481
481
                ms = (' ' * m + '*').ljust(cols)
482
 
                
 
482
 
483
483
                bar_str = '[' + ms + '] '
484
484
            else:
485
485
                bar_str = ''
491
491
        self.to_file.write('\r%-*.*s' % (self.width - 1, self.width - 1, m))
492
492
        self._have_output = True
493
493
        #self.to_file.flush()
494
 
            
 
494
 
495
495
    def clear(self):
496
496
        if self._have_output:
497
497
            self.to_file.write('\r%s\r' % (' ' * (self.width - 1)))
498
498
        self._have_output = False
499
 
        #self.to_file.flush()        
 
499
        #self.to_file.flush()
500
500
 
501
501
 
502
502
 
588
588
 
589
589
    if elapsed < 2.0:                   # not enough time to estimate
590
590
        return None
591
 
    
 
591
 
592
592
    total_duration = float(elapsed) * float(total) / float(current)
593
593
 
594
594
    if last_updates and len(last_updates) >= n_recent: