[Piglit] [PATCH] framework/log: Avoid carriage-return when stdout is not a TTY.

Ilia Mirkin imirkin at alum.mit.edu
Thu Jun 5 08:26:26 PDT 2014


On Thu, Jun 5, 2014 at 11:23 AM,  <jfonseca at vmware.com> wrote:
> 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.

Hm, perhaps "not a tty" should be synonymous with verbose mode where
it prints all the tests? (What is Jenkins? Some sort of continuous
build system?)

> ---
>  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
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list