diff options
| author | Shawn O. Pearce <sop@google.com> | 2010-05-27 16:48:36 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2010-05-27 16:48:36 -0700 |
| commit | f4f04d9fa8fda995974c9214eee42c3ea68b1125 (patch) | |
| tree | 2d0acc407a231e272c84e142a37bc231310c77b7 | |
| parent | 18afd7f679ab6271a34f4ec01e7755dd85c5dcf4 (diff) | |
| download | git-repo-f4f04d9fa8fda995974c9214eee42c3ea68b1125.tar.gz | |
Do not emit progress if stderr is not a tty
Avoids logging progress data into cron logs, etc.
Suggested-by: Michael Richardson <mcr@sandelman.ottawa.on.ca>
Change-Id: I4eefa2c282f0ca0a95a0185612b52e2146669e4c
Signed-off-by: Shawn O. Pearce <sop@google.com>
| -rw-r--r-- | progress.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/progress.py b/progress.py index b119b374..2ace7010 100644 --- a/progress.py +++ b/progress.py | |||
| @@ -13,10 +13,13 @@ | |||
| 13 | # See the License for the specific language governing permissions and | 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. | 14 | # limitations under the License. |
| 15 | 15 | ||
| 16 | import os | ||
| 16 | import sys | 17 | import sys |
| 17 | from time import time | 18 | from time import time |
| 18 | from trace import IsTrace | 19 | from trace import IsTrace |
| 19 | 20 | ||
| 21 | _NOT_TTY = not os.isatty(2) | ||
| 22 | |||
| 20 | class Progress(object): | 23 | class Progress(object): |
| 21 | def __init__(self, title, total=0): | 24 | def __init__(self, title, total=0): |
| 22 | self._title = title | 25 | self._title = title |
| @@ -29,7 +32,7 @@ class Progress(object): | |||
| 29 | def update(self, inc=1): | 32 | def update(self, inc=1): |
| 30 | self._done += inc | 33 | self._done += inc |
| 31 | 34 | ||
| 32 | if IsTrace(): | 35 | if _NOT_TTY or IsTrace(): |
| 33 | return | 36 | return |
| 34 | 37 | ||
| 35 | if not self._show: | 38 | if not self._show: |
| @@ -56,7 +59,7 @@ class Progress(object): | |||
| 56 | sys.stderr.flush() | 59 | sys.stderr.flush() |
| 57 | 60 | ||
| 58 | def end(self): | 61 | def end(self): |
| 59 | if IsTrace() or not self._show: | 62 | if _NOT_TTY or IsTrace() or not self._show: |
| 60 | return | 63 | return |
| 61 | 64 | ||
| 62 | if self._total <= 0: | 65 | if self._total <= 0: |
