diff options
author | Shawn O. Pearce <sop@google.com> | 2009-04-18 10:09:16 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-04-18 10:09:16 -0700 |
commit | 2810cbc7784e9a21e7001c31b65af94fd9ba7a5b (patch) | |
tree | d127eb13f4749cb40a4f58ce3a83985083751a8a /progress.py | |
parent | 6ed4e2834639d0b08686882d2e39cd736d66c688 (diff) | |
download | git-repo-2810cbc7784e9a21e7001c31b65af94fd9ba7a5b.tar.gz |
Only display a progress meter once we spend 0.5 seconds on a task
The point of the progress meter is to let the user know that the
task is progressing, and give them a chance to estimate when it will
be complete. If the task completes in under 0.5 seconds then it
is sufficiently fast enough that the user doesn't need to be kept
up-to-date on its progress; in fact showing the meter may just slow
the task down waiting on the tty to redraw.
We now delay the progress meter 0.5 seconds (or 1 second if the
Python time.time() function isn't accurate enough) to avoid any
really fast tasks, like a no-op local sync.
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'progress.py')
-rw-r--r-- | progress.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/progress.py b/progress.py index 98bb6429..b119b374 100644 --- a/progress.py +++ b/progress.py | |||
@@ -14,6 +14,7 @@ | |||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | import sys | 16 | import sys |
17 | from time import time | ||
17 | from trace import IsTrace | 18 | from trace import IsTrace |
18 | 19 | ||
19 | class Progress(object): | 20 | class Progress(object): |
@@ -22,6 +23,8 @@ class Progress(object): | |||
22 | self._total = total | 23 | self._total = total |
23 | self._done = 0 | 24 | self._done = 0 |
24 | self._lastp = -1 | 25 | self._lastp = -1 |
26 | self._start = time() | ||
27 | self._show = False | ||
25 | 28 | ||
26 | def update(self, inc=1): | 29 | def update(self, inc=1): |
27 | self._done += inc | 30 | self._done += inc |
@@ -29,6 +32,12 @@ class Progress(object): | |||
29 | if IsTrace(): | 32 | if IsTrace(): |
30 | return | 33 | return |
31 | 34 | ||
35 | if not self._show: | ||
36 | if 0.5 <= time() - self._start: | ||
37 | self._show = True | ||
38 | else: | ||
39 | return | ||
40 | |||
32 | if self._total <= 0: | 41 | if self._total <= 0: |
33 | sys.stderr.write('\r%s: %d, ' % ( | 42 | sys.stderr.write('\r%s: %d, ' % ( |
34 | self._title, | 43 | self._title, |
@@ -47,7 +56,7 @@ class Progress(object): | |||
47 | sys.stderr.flush() | 56 | sys.stderr.flush() |
48 | 57 | ||
49 | def end(self): | 58 | def end(self): |
50 | if IsTrace(): | 59 | if IsTrace() or not self._show: |
51 | return | 60 | return |
52 | 61 | ||
53 | if self._total <= 0: | 62 | if self._total <= 0: |