~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Martin Pool
  • Date: 2005-06-10 09:07:41 UTC
  • Revision ID: mbp@sourcefrog.net-20050610090741-3d5d7e200f80bab1
- limit rate at which progress bar is updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
    The output file should be in line-buffered or unbuffered mode.
85
85
    """
86
86
    SPIN_CHARS = r'/-\|'
 
87
    MIN_PAUSE = 0.1 # seconds
 
88
 
 
89
    start_time = None
 
90
    last_update = None
87
91
    
88
92
    def __init__(self,
89
93
                 to_file=sys.stderr,
93
97
                 show_bar=True,
94
98
                 show_count=True):
95
99
        object.__init__(self)
96
 
        self.start_time = None
97
100
        self.to_file = to_file
98
101
        self.suppressed = not _supports_progress(self.to_file)
99
102
        self.spin_pos = 0
112
115
 
113
116
    def update(self, msg, current_cnt, total_cnt=None):
114
117
        """Update and redraw progress bar."""
115
 
        if self.start_time is None:
116
 
            self.start_time = time.time()
 
118
        if self.suppressed:
 
119
            return
117
120
 
118
121
        # save these for the tick() function
119
122
        self.last_msg = msg
120
123
        self.last_cnt = current_cnt
121
124
        self.last_total = total_cnt
122
125
            
123
 
        if self.suppressed:
124
 
            return
 
126
        now = time.time()
 
127
        if self.start_time is None:
 
128
            self.start_time = now
 
129
        else:
 
130
            interval = now - self.last_update
 
131
            if interval > 0 and interval < self.MIN_PAUSE:
 
132
                return
125
133
 
 
134
        self.last_update = now
 
135
        
126
136
        width = _width()
127
137
 
128
138
        if total_cnt: