Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
spearce committed May 27, 2010
1 parent 18afd7f commit f4f04d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions progress.py
Expand Up @@ -13,10 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
from time import time
from trace import IsTrace

_NOT_TTY = not os.isatty(2)

class Progress(object):
def __init__(self, title, total=0):
self._title = title
Expand All @@ -29,7 +32,7 @@ def __init__(self, title, total=0):
def update(self, inc=1):
self._done += inc

if IsTrace():
if _NOT_TTY or IsTrace():
return

if not self._show:
Expand All @@ -56,7 +59,7 @@ def update(self, inc=1):
sys.stderr.flush()

def end(self):
if IsTrace() or not self._show:
if _NOT_TTY or IsTrace() or not self._show:
return

if self._total <= 0:
Expand Down

0 comments on commit f4f04d9

Please sign in to comment.