Mercurial > hg
annotate hgext/progress.py @ 25382:6084926366b9
summary: move the parents phase marker to commit line (issue4688)
The phase of the pending commit depends on the parent of the working directory
and on the phases.newcommit configuration.
First, this information rather depend on the commit line which describe the
pending commit.
Then, we only want to be advertised when the pending phase is going to be higher
than the default new commit phase.
So the format will change from
$ hg summary
parent: 2:ab91dfabc5ad
foo
parent: 3:24f1031ad244 tip
bar
branch: default
commit: 1 modified, 1 unknown, 1 unresolved (merge)
update: (current)
phases: 1 secret (secret)
to
parent: 2:ab91dfabc5ad
foo
parent: 3:24f1031ad244 tip
bar
branch: default
commit: 1 modified, 1 unknown, 1 unresolved (merge) (secret)
update: (current)
phases: 1 secret
author | Gilles Moris <gilles.moris@free.fr> |
---|---|
date | Fri, 29 May 2015 22:23:58 +0200 |
parents | 80c5b2666a96 |
children | 95f490136e75 |
rev | line source |
---|---|
10434 | 1 # progress.py show progress bars for some actions |
2 # | |
3 # Copyright (C) 2010 Augie Fackler <durin42@gmail.com> | |
4 # | |
15772
83a140752239
progress: Use the same GPL boilerplate as most hg files
Augie Fackler <durin42@gmail.com>
parents:
15662
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
83a140752239
progress: Use the same GPL boilerplate as most hg files
Augie Fackler <durin42@gmail.com>
parents:
15662
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
10434 | 7 |
8 """show progress bars for some actions | |
9 | |
10450 | 10 This extension uses the progress information logged by hg commands |
11 to draw progress bars that are as informative as possible. Some progress | |
10434 | 12 bars only offer indeterminate information, while others have a definite |
13 end point. | |
14 | |
15 The following settings are available:: | |
16 | |
17 [progress] | |
18 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
|
19 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
|
20 # 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
|
21 # be used instead. |
10434 | 22 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
|
23 format = topic bar number estimate # format of the progress bar |
10434 | 24 width = <none> # if set, the maximum width of the progress information |
25 # (that is, min(width, term width) will be used) | |
26 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
|
27 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
|
28 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
|
29 # disable is given |
10434 | 30 |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 characters. |
10434 | 36 """ |
37 | |
38 import sys | |
39 import time | |
23908
5502bd79d052
progress: add a lock to prepare for introducing a thread
Solomon Matthews <smat@fb.com>
parents:
23907
diff
changeset
|
40 import threading |
10434 | 41 |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
42 from mercurial.i18n import _ |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
23908
diff
changeset
|
43 # Note for extension authors: ONLY specify testedwith = 'internal' for |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
23908
diff
changeset
|
44 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
23908
diff
changeset
|
45 # be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
23908
diff
changeset
|
46 # leave the attribute unspecified. |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16676
diff
changeset
|
47 testedwith = 'internal' |
10434 | 48 |
21859
be4270d27a7e
progress: use 'encoding.trim' to trim output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19619
diff
changeset
|
49 from mercurial import encoding |
be4270d27a7e
progress: use 'encoding.trim' to trim output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19619
diff
changeset
|
50 |
10434 | 51 def spacejoin(*args): |
10452
59f8fff4f887
progress: simplify spacejoin()
Brodie Rao <me+hg@dackz.net>
parents:
10450
diff
changeset
|
52 return ' '.join(s for s in args if s) |
10434 | 53 |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
54 def shouldprint(ui): |
19404 | 55 return not ui.plain() and (ui._isatty(sys.stderr) or |
56 ui.configbool('progress', 'assume-tty')) | |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
57 |
13132
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
58 def fmtremaining(seconds): |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
59 if seconds < 60: |
13139
f4dd6aa16805
progress: explain format strings to translators
Martin Geisler <mg@aragost.com>
parents:
13132
diff
changeset
|
60 # 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
|
61 return _("%02ds") % (seconds) |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
62 minutes = seconds // 60 |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
63 if minutes < 60: |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
64 seconds -= minutes * 60 |
13139
f4dd6aa16805
progress: explain format strings to translators
Martin Geisler <mg@aragost.com>
parents:
13132
diff
changeset
|
65 # 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
|
66 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
|
67 # 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
|
68 minutes += 1 |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
69 hours = minutes // 60 |
24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
Augie Fackler <durin42@gmail.com>
parents:
13131
diff
changeset
|
70 minutes -= hours * 60 |
13236
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
71 if hours < 30: |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
72 # i18n: format X hours and YY minutes as "XhYYm" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
73 return _("%dh%02dm") % (hours, minutes) |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
74 # we're going to ignore minutes in this case |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
75 hours += 1 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
76 days = hours // 24 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
77 hours -= days * 24 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
78 if days < 15: |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
79 # i18n: format X days and YY hours as "XdYYh" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
80 return _("%dd%02dh") % (days, hours) |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
81 # we're going to ignore hours in this case |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
82 days += 1 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
83 weeks = days // 7 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
84 days -= weeks * 7 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
85 if weeks < 55: |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
86 # i18n: format X weeks and YY days as "XwYYd" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
87 return _("%dw%02dd") % (weeks, days) |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
88 # 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
|
89 weeks += 1 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
90 years = weeks // 52 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
91 weeks -= years * 52 |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
92 # i18n: format X years and YY weeks as "XyYYw" |
3f299f5d9a29
progress: handle days, weeks and years
timeless <timeless@gmail.com>
parents:
13154
diff
changeset
|
93 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
|
94 |
10434 | 95 class progbar(object): |
96 def __init__(self, ui): | |
97 self.ui = ui | |
23908
5502bd79d052
progress: add a lock to prepare for introducing a thread
Solomon Matthews <smat@fb.com>
parents:
23907
diff
changeset
|
98 self._refreshlock = threading.Lock() |
10434 | 99 self.resetstate() |
100 | |
101 def resetstate(self): | |
102 self.topics = [] | |
13130
f139f34ba330
progress: react more reasonably to nested progress topics
Augie Fackler <durin42@gmail.com>
parents:
12689
diff
changeset
|
103 self.topicstates = {} |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
104 self.starttimes = {} |
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
105 self.startvals = {} |
10434 | 106 self.printed = False |
107 self.lastprint = time.time() + float(self.ui.config( | |
108 'progress', 'delay', default=3)) | |
23906
e0ae0a4e4c7b
progress: move current topic to member variable
Solomon Matthews <smat@fb.com>
parents:
23905
diff
changeset
|
109 self.curtopic = None |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
110 self.lasttopic = None |
10434 | 111 self.indetcount = 0 |
112 self.refresh = float(self.ui.config( | |
113 '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
|
114 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
|
115 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
|
116 'progress', 'changedelay', default=1))) |
10434 | 117 self.order = self.ui.configlist( |
118 'progress', 'format', | |
13148
ab5fcc473fd1
progress: include time estimate as part of the default progress format
Augie Fackler <durin42@gmail.com>
parents:
13147
diff
changeset
|
119 default=['topic', 'bar', 'number', 'estimate']) |
10434 | 120 |
13131
c9ae7e096994
progress: Add estimated time remaining for long tasks
timeless <timeless@gmail.com>
parents:
13130
diff
changeset
|
121 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
|
122 if not shouldprint(self.ui): |
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
123 return |
10434 | 124 termwidth = self.width() |
125 self.printed = True | |
126 head = '' | |
127 needprogress = False | |
128 tail = '' | |
129 for indicator in self.order: | |
130 add = '' | |
131 if indicator == 'topic': | |
132 add = topic | |
133 elif indicator == 'number': | |
134 if total: | |
135 add = ('% ' + str(len(str(total))) + | |
136 's/%s') % (pos, total) | |
137 else: | |
138 add = str(pos) | |
139 elif indicator.startswith('item') and item: | |
140 slice = 'end' | |
141 if '-' in indicator: | |
142 wid = int(indicator.split('-')[1]) | |
143 elif '+' in indicator: | |
144 slice = 'beginning' | |
145 wid = int(indicator.split('+')[1]) | |
146 else: | |
147 wid = 20 | |
148 if slice == 'end': | |
21862
ba7f75e7f4e5
progress: use 'encoding.trim' to trim items in output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21860
diff
changeset
|
149 add = encoding.trim(item, wid, leftside=True) |
10434 | 150 else: |
21862
ba7f75e7f4e5
progress: use 'encoding.trim' to trim items in output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21860
diff
changeset
|
151 add = encoding.trim(item, wid) |
21863
f9c91c638378
progress: use 'encoding.colwidth' to get column width of items correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21862
diff
changeset
|
152 add += (wid - encoding.colwidth(add)) * ' ' |
10434 | 153 elif indicator == 'bar': |
154 add = '' | |
155 needprogress = True | |
156 elif indicator == 'unit' and unit: | |
157 add = unit | |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
158 elif indicator == 'estimate': |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
159 add = self.estimate(topic, pos, total, now) |
14280
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
160 elif indicator == 'speed': |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
161 add = self.speed(topic, pos, unit, now) |
10434 | 162 if not needprogress: |
163 head = spacejoin(head, add) | |
164 else: | |
13146
43575c67add3
progress: fix adding format elements after the progress bar
Augie Fackler <durin42@gmail.com>
parents:
13139
diff
changeset
|
165 tail = spacejoin(tail, add) |
10434 | 166 if needprogress: |
167 used = 0 | |
168 if head: | |
21860
e382cf9ec30b
progress: use 'encoding.colwidth' to get column width of output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21859
diff
changeset
|
169 used += encoding.colwidth(head) + 1 |
10434 | 170 if tail: |
21860
e382cf9ec30b
progress: use 'encoding.colwidth' to get column width of output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21859
diff
changeset
|
171 used += encoding.colwidth(tail) + 1 |
10434 | 172 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
|
173 if total and pos <= total: |
10434 | 174 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
|
175 bar = '=' * (amt - 1) |
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
176 if amt > 0: |
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
177 bar += '>' |
7edc649f9f7e
progress: make determinate bar more like wget progress bar
Brodie Rao <me+hg@dackz.net>
parents:
10452
diff
changeset
|
178 bar += ' ' * (progwidth - amt) |
10434 | 179 else: |
180 progwidth -= 3 | |
181 self.indetcount += 1 | |
182 # mod the count by twice the width so we can make the | |
183 # cursor bounce between the right and left sides | |
184 amt = self.indetcount % (2 * progwidth) | |
185 amt -= progwidth | |
186 bar = (' ' * int(progwidth - abs(amt)) + '<=>' + | |
187 ' ' * int(abs(amt))) | |
188 prog = ''.join(('[', bar , ']')) | |
189 out = spacejoin(head, prog, tail) | |
190 else: | |
191 out = spacejoin(head, tail) | |
21859
be4270d27a7e
progress: use 'encoding.trim' to trim output line correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19619
diff
changeset
|
192 sys.stderr.write('\r' + encoding.trim(out, termwidth)) |
14838
5d261fd00446
progress: add a changedelay to prevent parallel topics from flapping (issue2698)
Augie Fackler <durin42@gmail.com>
parents:
14837
diff
changeset
|
193 self.lasttopic = topic |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
194 sys.stderr.flush() |
10434 | 195 |
196 def clear(self): | |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
197 if not shouldprint(self.ui): |
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
198 return |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
199 sys.stderr.write('\r%s\r' % (' ' * self.width())) |
10434 | 200 |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
201 def complete(self): |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
202 if not shouldprint(self.ui): |
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
203 return |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
204 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
|
205 self.clear() |
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
206 else: |
10788
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
207 sys.stderr.write('\n') |
ca6ba6cac6cd
progress: use stderr instead of stdout; check stderr.isatty()
Augie Fackler <durin42@gmail.com>
parents:
10656
diff
changeset
|
208 sys.stderr.flush() |
10439
509f4ed56509
progress: correctly handle empty progress topic
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10434
diff
changeset
|
209 |
10434 | 210 def width(self): |
12689
c52c629ce19e
termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents:
12654
diff
changeset
|
211 tw = self.ui.termwidth() |
10434 | 212 return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
213 | |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
214 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
|
215 if total is None: |
e11c14f14491
progress: don't compute estimate without a total
Augie Fackler <durin42@gmail.com>
parents:
13148
diff
changeset
|
216 return '' |
13147
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
217 initialpos = self.startvals[topic] |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
218 target = total - initialpos |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
219 delta = pos - initialpos |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
220 if delta > 0: |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
221 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
|
222 if elapsed > float( |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
223 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
|
224 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
|
225 return fmtremaining(seconds) |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
226 return '' |
082f5be788d9
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler <durin42@gmail.com>
parents:
13146
diff
changeset
|
227 |
14280
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
228 def speed(self, topic, pos, unit, now): |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
229 initialpos = self.startvals[topic] |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
230 delta = pos - initialpos |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
231 elapsed = now - self.starttimes[topic] |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
232 if elapsed > float( |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
233 self.ui.config('progress', 'estimate', default=2)): |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
234 return _('%d %s/sec') % (delta / elapsed, unit) |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
235 return '' |
98e4d3914c2e
progress: add speed format
Martin Geisler <mg@aragost.com>
parents:
14247
diff
changeset
|
236 |
23907
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
237 def _oktoprint(self, now): |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
238 '''Check if conditions are met to print - e.g. changedelay elapsed''' |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
239 if (self.lasttopic is None # first time we printed |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
240 # not a topic change |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
241 or self.curtopic == self.lasttopic |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
242 # it's been long enough we should print anyway |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
243 or now - self.lastprint >= self.changedelay): |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
244 return True |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
245 else: |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
246 return False |
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
247 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
248 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
|
249 now = time.time() |
23908
5502bd79d052
progress: add a lock to prepare for introducing a thread
Solomon Matthews <smat@fb.com>
parents:
23907
diff
changeset
|
250 self._refreshlock.acquire() |
23905
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
251 try: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
252 if pos is None: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
253 self.starttimes.pop(topic, None) |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
254 self.startvals.pop(topic, None) |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
255 self.topicstates.pop(topic, None) |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
256 # reset the progress bar if this is the outermost topic |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
257 if self.topics and self.topics[0] == topic and self.printed: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
258 self.complete() |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
259 self.resetstate() |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
260 # truncate the list of topics assuming all topics within |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
261 # this one are also closed |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
262 if topic in self.topics: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
263 self.topics = self.topics[:self.topics.index(topic)] |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
264 # reset the last topic to the one we just unwound to, |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
265 # so that higher-level topics will be stickier than |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
266 # lower-level topics |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
267 if self.topics: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
268 self.lasttopic = self.topics[-1] |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
269 else: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
270 self.lasttopic = None |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
271 else: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
272 if topic not in self.topics: |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
273 self.starttimes[topic] = now |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
274 self.startvals[topic] = pos |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
275 self.topics.append(topic) |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
276 self.topicstates[topic] = pos, item, unit, total |
23906
e0ae0a4e4c7b
progress: move current topic to member variable
Solomon Matthews <smat@fb.com>
parents:
23905
diff
changeset
|
277 self.curtopic = topic |
23905
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
278 if now - self.lastprint >= self.refresh and self.topics: |
23907
63c7783a5928
progress: move update check into helper method
Solomon Matthews <smat@fb.com>
parents:
23906
diff
changeset
|
279 if self._oktoprint(now): |
23905
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
280 self.lastprint = now |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
281 self.show(now, topic, *self.topicstates[topic]) |
8b5b963ba95a
progress: add try/finally to make the diffs for the next commit more readable
Solomon Matthews <smat@fb.com>
parents:
21863
diff
changeset
|
282 finally: |
23908
5502bd79d052
progress: add a lock to prepare for introducing a thread
Solomon Matthews <smat@fb.com>
parents:
23907
diff
changeset
|
283 self._refreshlock.release() |
10434 | 284 |
14837
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
285 _singleton = None |
ec4ba216ddef
progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents:
14836
diff
changeset
|
286 |
10434 | 287 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
|
288 global _singleton |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
289 class progressui(ui.__class__): |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
290 _progbar = None |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
291 |
15662
06671371e634
progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents:
14838
diff
changeset
|
292 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
|
293 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
|
294 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 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
|
299 |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
300 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
|
301 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
|
302 self._progbar.clear() |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
303 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
|
304 |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
305 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
|
306 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
|
307 self._progbar.clear() |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11458
diff
changeset
|
308 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
|
309 |
10540
dd9d057465c1
progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents:
10523
diff
changeset
|
310 # 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
|
311 # 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
|
312 if ui.configbool('progress', 'disable'): |
dd9d057465c1
progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents:
10523
diff
changeset
|
313 return |
11458
ec21d91c79b3
progress: check stderr.isatty() before each print
Augie Fackler <durin42@gmail.com>
parents:
10891
diff
changeset
|
314 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
|
315 ui.__class__ = progressui |
10434 | 316 # we instantiate one globally shared progress bar to avoid |
317 # 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
|
318 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
|
319 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
|
320 _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
|
321 progressui._progbar = _singleton |
10434 | 322 |
323 def reposetup(ui, repo): | |
324 uisetup(repo.ui) |