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

Jose Fonseca jfonseca at vmware.com
Thu Jun 5 08:47:48 PDT 2014


----- Original Message -----
> 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? 

No, the current verbosity level is fine.  I just need "\n" instead of "\r".  For the same reason there is a sys.stdout.flush() -- so that I can see the output immediately.

> (What is Jenkins? Some sort of continuous
> build system?)

It's a continuous integration server. I use it to schedule mesa/piglit builds, and the testing of both across many platforms.

Jose


> 
> > ---
> >  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
> > https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/piglit&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=NMr9uy2iTjWVixC0wOcYCWEIYhfo80qKwRgdodpoDzA%3D%0A&m=FNt%2BBK4qrgRJfsKN%2BxKHASdaLIGEZIB2EQR8JpimJg4%3D%0A&s=7b5f7c6507fc56be773b80618a11873f44e61dbe0c05360d2ea75abb939d1a70
> 


More information about the Piglit mailing list