[rtems-tools PATCH 1/2] rtemstoolkit: Fix decoding unicode strings in output

Joel Sherrill joel at rtems.org
Fri Apr 19 14:13:23 UTC 2024


Please apply both. I think this was the only bad issue with rc2 on CentOS 7
or 8.

On Thu, Apr 18, 2024 at 10:09 PM <chrisj at rtems.org> wrote:

> From: Chris Johns <chrisj at rtems.org>
>
> ---
>  rtemstoolkit/execute.py | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py
> index 31d3a8a..c7d8134 100755
> --- a/rtemstoolkit/execute.py
> +++ b/rtemstoolkit/execute.py
> @@ -37,6 +37,7 @@
>  from __future__ import print_function
>
>  import functools
> +import codecs
>  import io
>  import os
>  import re
> @@ -203,6 +204,10 @@ class execute(object):
>                      stacktraces.trace()
>              if trace_threads:
>                  print('execute:_readthread: start')
> +            if sys.stdout.encoding is not None:
> +                decoder =
> codecs.getincrementaldecoder(sys.stdout.encoding)()
> +            else:
> +                decoder = None
>              count = 0
>              line = ''
>              try:
> @@ -222,8 +227,8 @@ class execute(object):
>                              _output_line(line + '\n', exe, prefix, out,
> count)
>                          break
>                      # str and bytes are the same type in Python2
> -                    if type(data) is not str and type(data) is bytes:
> -                        data = data.decode(sys.stdout.encoding)
> +                    if decoder is not None and type(data) is not str and
> type(data) is bytes:
> +                        data = decoder.decode(data)
>                      last_ch = data[-1]
>                      sd = (line + data).split('\n')
>                      if last_ch != '\n':
> @@ -382,6 +387,9 @@ class execute(object):
>          if self.verbose:
>              log.output(what + ': ' + cs)
>          log.trace('exe: %s' % (cs))
> +        if shell and self.shell_exe:
> +            command = arg_list(command)
> +            command[:0] = self.shell_exe
>          if not stdin and self.input:
>              stdin = subprocess.PIPE
>          if not stdout:
> --
> 2.39.3 (Apple Git-146)
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20240419/018f4d17/attachment.htm>


More information about the devel mailing list