annotate hgext/progress.py @ 25497:93b8b0049932

progress: move most extension code into a 'mercurial.progress' module This initiate the relocation of progress into core.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 07 Jun 2015 17:19:20 -0700
parents 95f490136e75
children 7a5335ed7e1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 # progress.py show progress bars for some actions
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 #
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 # Copyright (C) 2010 Augie Fackler <durin42@gmail.com>
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 """show progress bars for some actions
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9
10450
b4fd900569b1 progress: fix description
timeless <timeless@mozdev.org>
parents: 10441
diff changeset
10 This extension uses the progress information logged by hg commands
b4fd900569b1 progress: fix description
timeless <timeless@mozdev.org>
parents: 10441
diff changeset
11 to draw progress bars that are as informative as possible. Some progress
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12 bars only offer indeterminate information, while others have a definite
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 end point.
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15 The following settings are available::
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 [progress]
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 width = <none> # if set, the maximum width of the progress information
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 # (that is, min(width, term width) will be used)
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 """
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37
25497
93b8b0049932 progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25482
diff changeset
38 from mercurial import progress
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39
14837
ec4ba216ddef progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents: 14836
diff changeset
40 _singleton = None
ec4ba216ddef progress: make progress bar a singleton to avoid double-progress ui bugs
Augie Fackler <durin42@gmail.com>
parents: 14836
diff changeset
41
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 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
43 global _singleton
11555
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
44 class progressui(ui.__class__):
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
45 _progbar = None
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
46
15662
06671371e634 progress: check for ui.quiet and ui.debugflag before we write
David Soria Parra <dsp@php.net>
parents: 14838
diff changeset
47 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
48 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
49
11555
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
50 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
51 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
52 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
53 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
54
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
55 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
56 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
57 self._progbar.clear()
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
58 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
59
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
60 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
61 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
62 self._progbar.clear()
d8d0fc3988ca color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents: 11458
diff changeset
63 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
64
10540
dd9d057465c1 progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents: 10523
diff changeset
65 # 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
66 # 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
67 if ui.configbool('progress', 'disable'):
dd9d057465c1 progress: provide an explicit disable method for developers
Steve Borho <steve@borho.org>
parents: 10523
diff changeset
68 return
25497
93b8b0049932 progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25482
diff changeset
69 if progress.shouldprint(ui) and not ui.debugflag and not ui.quiet:
25482
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
70 dval = object()
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
71 if getattr(ui, '_progbar', dval) is dval:
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
72 ui.__class__ = progressui
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
73 # we instantiate one globally-shared progress bar to avoid
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
74 # competing progress bars when multiple UI objects get created
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
75 if not progressui._progbar:
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
76 if _singleton is None:
25497
93b8b0049932 progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25482
diff changeset
77 _singleton = progress.progbar(ui)
25482
95f490136e75 progress: stop double-wrapping of ui class
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25186
diff changeset
78 progressui._progbar = _singleton
10434
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 def reposetup(ui, repo):
ad104a786d35 Progress bar extension
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 uisetup(repo.ui)