From 0f00fbbed38757a2b0628341f172c69d9c4dd60a Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 21 Dec 2015 16:18:29 +0000 Subject: Don't show progress bars if stderr is being redirected to a file Currently the logs of our continuous builder (https://mason-x86-64.baserock.org) are filled with lots of this sort of crap: stage1-binutils-misc[ ] 2.4/73.0 MB stage1-binutils-misc[ ] 2.4/73.0 MB stage1-binutils-misc[ ] 2.4/73.0 MB stage1-binutils-misc[ ] 2.4/73.0 MB stage1-binutils-misc[# ] 2.4/73.0 MB stage1-binutils-misc[# ] 2.5/73.0 MB stage1-binutils-misc[# ] 2.5/73.0 MB ... Change-Id: I0b7a4c8421c3ecdd141fc8323d3001ae4fb44d9b --- morphlib/util.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/morphlib/util.py b/morphlib/util.py index 0ec071e4..94b0f4c4 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -767,13 +767,14 @@ class ProgressBar(object): self._empty_char = empty_char def show(self, progress): #pragma: no cover - blocks = int(progress / self._block_width); - - s = self.TEMPLATE % (self._label, self._progress_char * blocks, - self._empty_char * (self._width - blocks), - progress, self._expected_size, self._unit) - sys.stderr.write(s) - sys.stderr.flush() + if sys.stderr.isatty(): + blocks = int(progress / self._block_width); + + s = self.TEMPLATE % (self._label, self._progress_char * blocks, + self._empty_char * (self._width - blocks), + progress, self._expected_size, self._unit) + sys.stderr.write(s) + sys.stderr.flush() def schemas_directory(): # pragma: no cover -- cgit v1.2.1