From bc8971d122a02ed823acf0758da267dccc584f98 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 12 May 2016 08:30:35 +0100 Subject: bitbake: bitbake: Convert to python 3 megacommit This needs breaking up into smaller changes. (Bitbake rev: cf51f19aed208a75d38c14cd585d9b9f115e3ba3) Signed-off-by: Richard Purdie --- bitbake/lib/bb/process.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'bitbake/lib/bb/process.py') diff --git a/bitbake/lib/bb/process.py b/bitbake/lib/bb/process.py index 1c07f2d9b7..28b899694a 100644 --- a/bitbake/lib/bb/process.py +++ b/bitbake/lib/bb/process.py @@ -17,7 +17,7 @@ class CmdError(RuntimeError): self.msg = msg def __str__(self): - if not isinstance(self.command, basestring): + if not isinstance(self.command, str): cmd = subprocess.list2cmdline(self.command) else: cmd = self.command @@ -97,6 +97,8 @@ def _logged_communicate(pipe, log, input, extrafiles): try: while pipe.poll() is None: rlist = rin + stdoutbuf = b"" + stderrbuf = b"" try: r,w,e = select.select (rlist, [], [], 1) except OSError as e: @@ -104,16 +106,26 @@ def _logged_communicate(pipe, log, input, extrafiles): raise if pipe.stdout in r: - data = pipe.stdout.read() - if data is not None: - outdata.append(data) - log.write(data) + data = stdoutbuf + pipe.stdout.read() + if data is not None and len(data) > 0: + try: + data = data.decode("utf-8") + outdata.append(data) + log.write(data) + stdoutbuf = b"" + except UnicodeDecodeError: + stdoutbuf = data if pipe.stderr in r: - data = pipe.stderr.read() - if data is not None: - errdata.append(data) - log.write(data) + data = stderrbuf + pipe.stderr.read() + if data is not None and len(data) > 0: + try: + data = data.decode("utf-8") + errdata.append(data) + log.write(data) + stderrbuf = b"" + except UnicodeDecodeError: + stderrbuf = data readextras(r) @@ -135,7 +147,7 @@ def run(cmd, input=None, log=None, extrafiles=None, **options): if not extrafiles: extrafiles = [] - if isinstance(cmd, basestring) and not "shell" in options: + if isinstance(cmd, str) and not "shell" in options: options["shell"] = True try: -- cgit v1.2.3-54-g00ecf