Mercurial > hg
annotate hgext/progress.py @ 15692:65d1c54ca705
merge with i18n
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 19 Dec 2011 14:04:26 -0600 |
parents | 06671371e634 |
children | 83a140752239 |
rev | line source |
---|---|
10434 | 1 # progress.py show progress bars for some actions |
2 # | |
3 # Copyright (C) 2010 Augie Fackler <durin42@gmail.com> | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify it | |
6 # under the terms of the GNU General Public License as published by the | |
7 # Free Software Foundation; either version 2 of the License, or (at your | |
8 # option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, but | |
11 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | |
13 # Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License along | |
16 # with this program; if not, write to the Free Software Foundation, Inc., | |
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | |
19 """show progress bars for some actions | |
20 | |
10450 | 21 This extension uses the progress information logged by hg commands |
22 to draw progress bars that are as informative as possible. Some progress | |
10434 | 23 bars only offer indeterminate information, while others have a definite |
24 end point. | |
25 | |
26 The following settings are available:: | |
27 | |
28 [progress] | |
29 delay = 3 # number of seconds (float) before showing the progress bar | |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
30 changedelay = 1 # changedelay: minimum delay before showing a new topic. |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
31 # If set to less than 3 * refresh, that value will |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
32 # be used instead. |
10434 | 33 refresh = 0.1 # time in seconds between refreshes of the progress bar |
13148
ab5fcc473fd1
progress: include time estimate as part of the default progress format
Augie Fackler <durin42@gmail.com>
parents:
13147
diff
changeset
|
34 format = topic bar number estimate # format of the progress bar |
10434 | 35 width = <none> # if set, the maximum width of the progress information |
36 # (that is, min(width, term width) will be used) | |
37 clear-complete = True # clear the progress bar after it's done | |
10656
f6ee02933af9
progress: document progress.disable config option
Augie Fackler <durin42@gmail.com>
parents:
10594
diff
changeset
|
38 disable = False # if true, don't show a progress bar |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
39 assume-tty = False # if true, ALWAYS show a progress bar, unless |
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
40 # disable is given |
10434 | 41 |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
42 Valid entries for the format field are topic, bar, number, unit, |
14280
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
43 estimate, speed, and item. item defaults to the last 20 characters of |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
44 the item, but this can be changed by adding either ``-<num>`` which |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
45 would take the last num characters, or ``+<num>`` for the first num |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
46 characters. |
10434 | 47 """ |
48 | |
49 import sys | |
50 import time | |
51 | |
14515
76f295eaed86
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara <idankk86@gmail.com>
parents:
14280
diff
changeset
|
52 from mercurial import util |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
53 from mercurial.i18n import _ |
10434 | 54 |
55 def spacejoin(*args): | |
10452
59f8fff4f887
progress: simplify spacejoin()
Brodie Rao <me+hg@dackz.net>
parents:
10450
diff
changeset
|
56 return ' '.join(s for s in args if s) |
10434 | 57 |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
58 def shouldprint(ui): |
14836
925cab23d7d5
progress: remove superfluous parens
Augie Fackler <durin42@gmail.com>
parents:
14515
diff
changeset
|
59 return util.isatty(sys.stderr) or ui.configbool('progress', 'assume-tty') |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
60 |
13132
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
61 def fmtremaining(seconds): |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
62 if seconds < 60: |
13139
f4dd6aa16805
progress: explain format strings to translators
Martin Geisler <mg@aragost.com>
parents:
13132
diff
changeset
|
63 # i18n: format XX seconds as "XXs" |
13132
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
64 return _("%02ds") % (seconds) |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
65 minutes = seconds // 60 |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
66 if minutes < 60: |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
67 seconds -= minutes * 60 |
13139
f4dd6aa16805
progress: explain format strings to translators
Martin Geisler <mg@aragost.com>
parents:
13132
diff
changeset
|
68 # i18n: format X minutes and YY seconds as "XmYYs" |
13132
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
69 return _("%dm%02ds") % (minutes, seconds) |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
70 # we're going to ignore seconds in this case |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
71 minutes += 1 |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
72 hours = minutes // 60 |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
73 minutes -= hours * 60 |
13236
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
74 if hours < 30: |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
75 # i18n: format X hours and YY minutes as "XhYYm" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
76 return _("%dh%02dm") % (hours, minutes) |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
77 # we're going to ignore minutes in this case |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
78 hours += 1 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
79 days = hours // 24 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
80 hours -= days * 24 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
81 if days < 15: |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
82 # i18n: format X days and YY hours as "XdYYh" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
83 return _("%dd%02dh") % (days, hours) |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
84 # we're going to ignore hours in this case |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
85 days += 1 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
86 weeks = days // 7 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
87 days -= weeks * 7 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
88 if weeks < 55: |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
89 # i18n: format X weeks and YY days as "XwYYd" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
90 return _("%dw%02dd") % (weeks, days) |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
91 # we're going to ignore days and treat a year as 52 weeks |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
92 weeks += 1 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
93 years = weeks // 52 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
94 weeks -= years * 52 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
95 # i18n: format X years and YY weeks as "XyYYw" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
96 return _("%dy%02dw") % (years, weeks) |
13132
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
97 |
10434 | 98 class progbar(object): |
99 def __init__(self, ui): | |
100 self.ui = ui | |
101 self.resetstate() | |
102 | |
103 def resetstate(self): | |
104 self.topics = [] | |
13130
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
105 self.topicstates = {} |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
106 self.starttimes = {} |
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
107 self.startvals = {} |
10434 | 108 self.printed = False |
109 self.lastprint = time.time() + float(self.ui.config( | |
110 'progress', 'delay', default=3)) | |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
111 self.lasttopic = None |
10434 | 112 self.indetcount = 0 |
113 self.refresh = float(self.ui.config( | |
114 'progress', 'refresh', default=0.1)) | |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
115 self.changedelay = max(3 * self.refresh, |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
116 float(self.ui.config( |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
117 'progress', 'changedelay', default=1))) |
10434 | 118 self.order = self.ui.configlist( |
119 'progress', 'format', | |
13148
ab5fcc473fd1
progress: include time estimate as part of the default progress format
Augie Fackler <durin42@gmail.com>
parents:
13147
diff
changeset
|
120 default=['topic', 'bar', 'number', 'estimate']) |
10434 | 121 |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
122 def show(self, now, topic, pos, item, unit, total): |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
123 if not shouldprint(self.ui): |
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
124 return |
10434 | 125 termwidth = self.width() |
126 self.printed = True | |
127 head = '' | |
128 needprogress = False | |
129 tail = '' | |
130 for indicator in self.order: | |
131 add = '' | |
132 if indicator == 'topic': | |
133 add = topic | |
134 elif indicator == 'number': | |
135 if total: | |
136 add = ('% ' + str(len(str(total))) + | |
137 's/%s') % (pos, total) | |
138 else: | |
139 add = str(pos) | |
140 elif indicator.startswith('item') and item: | |
141 slice = 'end' | |
142 if '-' in indicator: | |
143 wid = int(indicator.split('-')[1]) | |
144 elif '+' in indicator: | |
145 slice = 'beginning' | |
146 wid = int(indicator.split('+')[1]) | |
147 else: | |
148 wid = 20 | |
149 if slice == 'end': | |
150 add = item[-wid:] | |
151 else: | |
152 add = item[:wid] | |
153 add += (wid - len(add)) * ' ' | |
154 elif indicator == 'bar': | |
155 add = '' | |
156 needprogress = True | |
157 elif indicator == 'unit' and unit: | |
158 add = unit | |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
159 elif indicator == 'estimate': |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
160 add = self.estimate(topic, pos, total, now) |
14280
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
161 elif indicator == 'speed': |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
162 add = self.speed(topic, pos, unit, now) |
10434 | 163 if not needprogress: |
164 head = spacejoin(head, add) | |
165 else: | |
13146
43575c67add3
progress: fix adding format elements after the progress bar
Augie Fackler <durin42@gmail.com>
parents:
13139
diff
changeset
|
166 tail = spacejoin(tail, add) |
10434 | 167 if needprogress: |
168 used = 0 | |
169 if head: | |
170 used += len(head) + 1 | |
171 if tail: | |
172 used += len(tail) + 1 | |
173 progwidth = termwidth - used - 3 | |
10891
83af68e38be3
progress: fall back to indeterminate progress if position is >= total
Augie Fackler <durin42@gmail.com>
parents:
10815
diff
changeset
|
174 if total and pos <= total: |
10434 | 175 amt = pos * progwidth // total |
10453
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
176 bar = '=' * (amt - 1) |
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
177 if amt > 0: |
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
178 bar += '>' |
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
179 bar += ' ' * (progwidth - amt) |
10434 | 180 else: |
181 progwidth -= 3 | |
182 self.indetcount += 1 | |
183 # mod the count by twice the width so we can make the | |
184 # cursor bounce between the right and left sides | |
185 amt = self.indetcount % (2 * progwidth) | |
186 amt -= progwidth | |
187 bar = (' ' * int(progwidth - abs(amt)) + '<=>' + | |
188 ' ' * int(abs(amt))) | |
189 prog = ''.join(('[', bar , ']')) | |
190 out = spacejoin(head, prog, tail) | |
191 else: | |
192 out = spacejoin(head, tail) | |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
193 sys.stderr.write('\r' + out[:termwidth]) |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
194 self.lasttopic = topic |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
195 sys.stderr.flush() |
10434 | 196 |
197 def clear(self): | |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
198 if not shouldprint(self.ui): |
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
199 return |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
200 sys.stderr.write('\r%s\r' % (' ' * self.width())) |
10434 | 201 |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
202 def complete(self): |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
203 if not shouldprint(self.ui): |
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
204 return |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
205 if self.ui.configbool('progress', 'clear-complete', default=True): |
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
206 self.clear() |
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
207 else: |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
208 sys.stderr.write('\n') |
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
209 sys.stderr.flush() |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
210 |
10434 | 211 def width(self): |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12654
diff
changeset
|
212 tw = self.ui.termwidth() |
10434 | 213 return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
214 | |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
215 def estimate(self, topic, pos, total, now): |
13154
e11c14f14491
progress: don't compute estimate without a total
Augie Fackler <durin42@gmail.com>
parents:
13148
diff
changeset
|
216 if total is None: |
e11c14f14491
progress: don't compute estimate without a total
Augie Fackler <durin42@gmail.com>
parents:
13148
diff
changeset
|
217 return '' |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
218 initialpos = self.startvals[topic] |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
219 target = total - initialpos |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
220 delta = pos - initialpos |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
221 if delta > 0: |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
222 elapsed = now - self.starttimes[topic] |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
223 if elapsed > float( |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
224 self.ui.config('progress', 'estimate', default=2)): |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
225 seconds = (elapsed * (target - delta)) // delta + 1 |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
226 return fmtremaining(seconds) |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
227 return '' |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
228 |
14280
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
229 def speed(self, topic, pos, unit, now): |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
230 initialpos = self.startvals[topic] |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
231 delta = pos - initialpos |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
232 elapsed = now - self.starttimes[topic] |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
233 if elapsed > float( |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
234 self.ui.config('progress', 'estimate', default=2)): |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
235 return _('%d %s/sec') % (delta / elapsed, unit) |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
236 return '' |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
237 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
238 def progress(self, topic, pos, item='', unit='', total=None): |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
239 now = time.time() |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
240 if pos is None: |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
241 self.starttimes.pop(topic, None) |
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
242 self.startvals.pop(topic, None) |
13130
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
243 self.topicstates.pop(topic, None) |
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
244 # reset the progress bar if this is the outermost topic |
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
245 if self.topics and self.topics[0] == topic and self.printed: |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
246 self.complete() |
10441
dc0d1ca2d378
progress: only reset state if finishing progress for the current topic
Augie Fackler <durin42@gmail.com>
parents:
10439
diff
changeset
|
247 self.resetstate() |
13130
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
248 # truncate the list of topics assuming all topics within |
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
249 # this one are also closed |
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
250 if topic in self.topics: |
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
251 self.topics = self.topics[:self.topics.index(topic)] |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
252 else: |
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
253 if topic not in self.topics: |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
254 self.starttimes[topic] = now |
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
255 self.startvals[topic] = pos |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
256 self.topics.append(topic) |
13130
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
257 self.topicstates[topic] = pos, item, unit, total |
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
258 if now - self.lastprint >= self.refresh and self.topics: |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
259 if (self.lasttopic is None # first time we printed |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
260 # not a topic change |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
261 or topic == self.lasttopic |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
262 # it's been long enough we should print anyway |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
263 or now - self.lastprint >= self.changedelay): |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
264 self.lastprint = now |
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
265 self.show(now, topic, *self.topicstates[topic]) |
10434 | 266 |
14837
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
267 _singleton = None |
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
268 |
10434 | 269 def uisetup(ui): |
14837
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
270 global _singleton |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
271 class progressui(ui.__class__): |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
272 _progbar = None |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
273 |
15662
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
274 def _quiet(self): |
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
275 return self.debugflag or self.quiet |
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
276 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
277 def progress(self, *args, **opts): |
15662
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
278 if not self._quiet(): |
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
279 self._progbar.progress(*args, **opts) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
280 return super(progressui, self).progress(*args, **opts) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
281 |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
282 def write(self, *args, **opts): |
15662
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
283 if not self._quiet() and self._progbar.printed: |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
284 self._progbar.clear() |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
285 return super(progressui, self).write(*args, **opts) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
286 |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
287 def write_err(self, *args, **opts): |
15662
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
288 if not self._quiet() and self._progbar.printed: |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
289 self._progbar.clear() |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
290 return super(progressui, self).write_err(*args, **opts) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
291 |
10540
dd9d057465c1
progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents:
10523
diff
changeset
|
292 # Apps that derive a class from ui.ui() can use |
dd9d057465c1
progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents:
10523
diff
changeset
|
293 # setconfig('progress', 'disable', 'True') to disable this extension |
dd9d057465c1
progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents:
10523
diff
changeset
|
294 if ui.configbool('progress', 'disable'): |
dd9d057465c1
progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents:
10523
diff
changeset
|
295 return |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
296 if shouldprint(ui) and not ui.debugflag and not ui.quiet: |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
297 ui.__class__ = progressui |
10434 | 298 # we instantiate one globally shared progress bar to avoid |
299 # competing progress bars when multiple UI objects get created | |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
300 if not progressui._progbar: |
14837
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
301 if _singleton is None: |
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
302 _singleton = progbar(ui) |
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
303 progressui._progbar = _singleton |
10434 | 304 |
305 def reposetup(ui, repo): | |
306 uisetup(repo.ui) |