[Piglit] [PATCH] framework/log: Avoid carriage-return when stdout is not a TTY.
jfonseca at vmware.com
jfonseca at vmware.com
Thu Jun 5 08:23:00 PDT 2014
From: José Fonseca <jfonseca at vmware.com>
Otherwise Jenkins won't show any progress while piglit is running.
PS: Another alternative would be to detect the presence of
JENKINS_HOME/HUDSON_HOME environment variables. I'm happy either way.
---
framework/log.py | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/framework/log.py b/framework/log.py
index e5154aa..d261dbb 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -43,8 +43,18 @@ class Log(object):
'timeout'])
self.__summary = collections.defaultdict(lambda: 0)
self.__lastlength = 0
+ self.__tty = sys.stdout.isatty()
+
+ self.__output = "[{percent}] {summary} {running}"
+
+ # Some automation tools (e.g, Jenkins) will buffer all output until
+ # newline, so don't use carriage return character if the stdout is not
+ # a TTY.
+ if self.__tty:
+ self.__output += "\r"
+ else:
+ self.__output += "\n"
- self.__output = "[{percent}] {summary} {running}\r"
if verbose:
self.__output = "{result} :: {name}\n" + self.__output
@@ -53,13 +63,14 @@ class Log(object):
def _write_output(self, output):
""" write the output to stdout, ensuring any previous line is cleared """
- length = len(output)
- if self.__lastlength > length:
- output = "{0}{1}{2}".format(output[:-1],
- " " * (self.__lastlength - length),
- output[-1])
+ if self.__tty:
+ length = len(output)
+ if self.__lastlength > length:
+ output = "{0}{1}{2}".format(output[:-1],
+ " " * (self.__lastlength - length),
+ output[-1])
- self.__lastlength = length
+ self.__lastlength = length
sys.stdout.write(output)
--
1.9.1
More information about the Piglit
mailing list