[Piglit] [PATCH 1/2] framework/log.py: ensure any previous output is cleared
Dylan Baker
baker.dylan.c at gmail.com
Tue Mar 25 13:46:44 PDT 2014
On Friday, March 21, 2014 13:55:10 Thomas Wood wrote:
> If the new summary line is shorter than the previous one, clear the
> remaining characters.
>
> Signed-off-by: Thomas Wood <thomas.wood at intel.com>
> ---
> framework/log.py | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/framework/log.py b/framework/log.py
> index cdc3e94..96f757e 100644
> --- a/framework/log.py
> +++ b/framework/log.py
> @@ -41,6 +41,8 @@ class Log(object):
> self.__summary_keys = set(['pass', 'fail', 'warn', 'crash', 'skip',
> 'dmesg-warn', 'dmesg-fail', 'dry-run', 'timeout']) self.__summary =
> collections.defaultdict(lambda: 0)
> + self.__verbose = verbose
Am I missing something or is this unused?
> + self.__lastlength = 0
>
> self.__output = "[{percent}] {summary} {running}\r"
> if verbose:
> @@ -64,11 +66,19 @@ class Log(object):
>
> def __print(self, name, result):
> """ Do the actual printing """
> - sys.stdout.write(self.__output.format(**{'percent':
> self._percent(), -
> 'running': self._running(), -
> 'summary': self._summary(), -
> 'name': name,
> - 'result': result}))
> + output = self.__output.format(**{'percent': self._percent(),
> + 'running': self._running(),
> + 'summary': self._summary(),
> + 'name': name,
> + 'result': result})
> +
> + length = len(output)
> + if self.__lastlength > length:
> + output = output[:-1] + (" " * (self.__lastlength - length)) +
> '\r' +
I think using str.format() would make this more readable:
output = "{0}{1}\n".format(output[:-1], " " * (self.__lastlength - length))
Personally I would use a generator:
" ".join('' for x in xrange(self.__lastlength - length)), but there is nothing
wrong with what you did, consider it nothing more than a suggestion
> + self.__lastlength = length
> +
> + sys.stdout.write(output)
>
> # Need to flush explicitly, otherwise it all gets buffered without
> a # newline.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140325/cc773c11/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140325/cc773c11/attachment-0001.sig>
More information about the Piglit
mailing list