~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Robert Collins
  • Date: 2005-10-18 06:42:17 UTC
  • mfrom: (0.2.1)
  • mto: This revision was merged to the branch mainline in revision 1463.
  • Revision ID: robertc@robertcollins.net-20051018064217-e810bd94c74a9ad1
Factor out the guts of 'pull' from the command into WorkingTree.pull().
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
import sys
40
40
import time
41
41
import os
42
 
from collections import deque
43
42
 
44
43
 
45
44
def _width():
167
166
        self.width = _width()
168
167
        self.start_time = None
169
168
        self.last_update = None
170
 
        self.last_updates = deque()
171
169
    
172
170
 
173
171
    def throttle(self):
181
179
            if interval > 0 and interval < self.MIN_PAUSE:
182
180
                return True
183
181
 
184
 
        self.last_updates.append(now - self.last_update)
185
182
        self.last_update = now
186
183
        return False
187
184
        
209
206
            return 
210
207
        
211
208
        if self.show_eta and self.start_time and total_cnt:
212
 
            eta = get_eta(self.start_time, current_cnt, total_cnt,
213
 
                    last_updates = self.last_updates)
 
209
            eta = get_eta(self.start_time, current_cnt, total_cnt)
214
210
            eta_str = " " + str_tdelta(eta)
215
211
        else:
216
212
            eta_str = ""
284
280
                             delt % 60)
285
281
 
286
282
 
287
 
def get_eta(start_time, current, total, enough_samples=3, last_updates=None, n_recent=10):
 
283
def get_eta(start_time, current, total, enough_samples=3):
288
284
    if start_time is None:
289
285
        return None
290
286
 
306
302
 
307
303
    assert total_duration >= elapsed
308
304
 
309
 
    if last_updates and len(last_updates) >= n_recent:
310
 
        while len(last_updates) > n_recent:
311
 
            last_updates.popleft()
312
 
        avg = sum(last_updates) / float(len(last_updates))
313
 
        time_left = avg * (total - current)
314
 
 
315
 
        old_time_left = total_duration - elapsed
316
 
 
317
 
        # We could return the average, or some other value here
318
 
        return (time_left + old_time_left) / 2
319
 
 
320
305
    return total_duration - elapsed
321
306
 
322
307