##// END OF EJS Templates
progress: Add estimated time remaining for long tasks...
timeless -
r13131:c9ae7e09 default
parent child Browse files
Show More
@@ -45,6 +45,7 b' num characters, or ``+<num>`` for the fi'
45 import sys
45 import sys
46 import time
46 import time
47
47
48 from mercurial.i18n import _
48 from mercurial import util
49 from mercurial import util
49
50
50 def spacejoin(*args):
51 def spacejoin(*args):
@@ -62,6 +63,8 b' class progbar(object):'
62 def resetstate(self):
63 def resetstate(self):
63 self.topics = []
64 self.topics = []
64 self.topicstates = {}
65 self.topicstates = {}
66 self.starttimes = {}
67 self.startvals = {}
65 self.printed = False
68 self.printed = False
66 self.lastprint = time.time() + float(self.ui.config(
69 self.lastprint = time.time() + float(self.ui.config(
67 'progress', 'delay', default=3))
70 'progress', 'delay', default=3))
@@ -72,7 +75,7 b' class progbar(object):'
72 'progress', 'format',
75 'progress', 'format',
73 default=['topic', 'bar', 'number'])
76 default=['topic', 'bar', 'number'])
74
77
75 def show(self, topic, pos, item, unit, total):
78 def show(self, now, topic, pos, item, unit, total):
76 if not shouldprint(self.ui):
79 if not shouldprint(self.ui):
77 return
80 return
78 termwidth = self.width()
81 termwidth = self.width()
@@ -121,6 +124,26 b' class progbar(object):'
121 used += len(tail) + 1
124 used += len(tail) + 1
122 progwidth = termwidth - used - 3
125 progwidth = termwidth - used - 3
123 if total and pos <= total:
126 if total and pos <= total:
127 initial = self.startvals[topic]
128 target = total - initial
129 delta = pos - initial
130 if delta > 0:
131 elapsed = now - self.starttimes[topic]
132 if elapsed > float(
133 self.ui.config('progress', 'estimate', default=2)):
134 seconds = (elapsed * (target - delta)) // delta + 1
135 minutes = seconds // 60
136 if minutes < 10:
137 seconds -= minutes * 60
138 remaining = _("%dm%02ds") % (minutes, seconds)
139 else:
140 # we're going to ignore seconds in this case
141 minutes += 1
142 hours = minutes // 60
143 minutes -= hours * 60
144 remaining = _("%dh%02dm") % (hours, minutes)
145 progwidth -= len(remaining) + 1
146 tail = spacejoin(tail, remaining)
124 amt = pos * progwidth // total
147 amt = pos * progwidth // total
125 bar = '=' * (amt - 1)
148 bar = '=' * (amt - 1)
126 if amt > 0:
149 if amt > 0:
@@ -161,7 +184,10 b' class progbar(object):'
161 return min(int(self.ui.config('progress', 'width', default=tw)), tw)
184 return min(int(self.ui.config('progress', 'width', default=tw)), tw)
162
185
163 def progress(self, topic, pos, item='', unit='', total=None):
186 def progress(self, topic, pos, item='', unit='', total=None):
187 now = time.time()
164 if pos is None:
188 if pos is None:
189 self.starttimes.pop(topic, None)
190 self.startvals.pop(topic, None)
165 self.topicstates.pop(topic, None)
191 self.topicstates.pop(topic, None)
166 # reset the progress bar if this is the outermost topic
192 # reset the progress bar if this is the outermost topic
167 if self.topics and self.topics[0] == topic and self.printed:
193 if self.topics and self.topics[0] == topic and self.printed:
@@ -173,13 +199,14 b' class progbar(object):'
173 self.topics = self.topics[:self.topics.index(topic)]
199 self.topics = self.topics[:self.topics.index(topic)]
174 else:
200 else:
175 if topic not in self.topics:
201 if topic not in self.topics:
202 self.starttimes[topic] = now
203 self.startvals[topic] = pos
176 self.topics.append(topic)
204 self.topics.append(topic)
177 now = time.time()
178 self.topicstates[topic] = pos, item, unit, total
205 self.topicstates[topic] = pos, item, unit, total
179 if now - self.lastprint >= self.refresh and self.topics:
206 if now - self.lastprint >= self.refresh and self.topics:
180 self.lastprint = now
207 self.lastprint = now
181 current = self.topics[-1]
208 current = self.topics[-1]
182 self.show(current, *self.topicstates[current])
209 self.show(now, topic, *self.topicstates[topic])
183
210
184 def uisetup(ui):
211 def uisetup(ui):
185 class progressui(ui.__class__):
212 class progressui(ui.__class__):
General Comments 0
You need to be logged in to leave comments. Login now