comparison hgext/progress.py @ 14280:98e4d3914c2e

progress: add speed format This is not enabled by default, but the user can add it by setting progress.format. We might want to let the estimate format output a speed instead of an ETA if there is not total. Currently estimate just returns the empty string in that case.
author Martin Geisler <mg@aragost.com>
date Mon, 09 May 2011 16:41:45 +0200
parents c9720ada999c
children 76f295eaed86
comparison
equal deleted inserted replaced
14279:b039b667515d 14280:98e4d3914c2e
35 disable = False # if true, don't show a progress bar 35 disable = False # if true, don't show a progress bar
36 assume-tty = False # if true, ALWAYS show a progress bar, unless 36 assume-tty = False # if true, ALWAYS show a progress bar, unless
37 # disable is given 37 # disable is given
38 38
39 Valid entries for the format field are topic, bar, number, unit, 39 Valid entries for the format field are topic, bar, number, unit,
40 estimate, and item. item defaults to the last 20 characters of the 40 estimate, speed, and item. item defaults to the last 20 characters of
41 item, but this can be changed by adding either ``-<num>`` which would 41 the item, but this can be changed by adding either ``-<num>`` which
42 take the last num characters, or ``+<num>`` for the first num 42 would take the last num characters, or ``+<num>`` for the first num
43 characters. 43 characters.
44 """ 44 """
45 45
46 import sys 46 import sys
47 import time 47 import time
149 needprogress = True 149 needprogress = True
150 elif indicator == 'unit' and unit: 150 elif indicator == 'unit' and unit:
151 add = unit 151 add = unit
152 elif indicator == 'estimate': 152 elif indicator == 'estimate':
153 add = self.estimate(topic, pos, total, now) 153 add = self.estimate(topic, pos, total, now)
154 elif indicator == 'speed':
155 add = self.speed(topic, pos, unit, now)
154 if not needprogress: 156 if not needprogress:
155 head = spacejoin(head, add) 157 head = spacejoin(head, add)
156 else: 158 else:
157 tail = spacejoin(tail, add) 159 tail = spacejoin(tail, add)
158 if needprogress: 160 if needprogress:
214 self.ui.config('progress', 'estimate', default=2)): 216 self.ui.config('progress', 'estimate', default=2)):
215 seconds = (elapsed * (target - delta)) // delta + 1 217 seconds = (elapsed * (target - delta)) // delta + 1
216 return fmtremaining(seconds) 218 return fmtremaining(seconds)
217 return '' 219 return ''
218 220
221 def speed(self, topic, pos, unit, now):
222 initialpos = self.startvals[topic]
223 delta = pos - initialpos
224 elapsed = now - self.starttimes[topic]
225 if elapsed > float(
226 self.ui.config('progress', 'estimate', default=2)):
227 return _('%d %s/sec') % (delta / elapsed, unit)
228 return ''
229
219 def progress(self, topic, pos, item='', unit='', total=None): 230 def progress(self, topic, pos, item='', unit='', total=None):
220 now = time.time() 231 now = time.time()
221 if pos is None: 232 if pos is None:
222 self.starttimes.pop(topic, None) 233 self.starttimes.pop(topic, None)
223 self.startvals.pop(topic, None) 234 self.startvals.pop(topic, None)