summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/process.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-12 08:30:35 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-02 08:24:02 +0100
commit0f2c59367a649de5f57acdccfb4f1fdba9cde730 (patch)
tree7a3558a3e08e690fbb0b5bdc4044316f9ab4bbcb /bitbake/lib/bb/process.py
parentef1df516512587ad415f76a9626620992d660e45 (diff)
downloadpoky-0f2c59367a649de5f57acdccfb4f1fdba9cde730.tar.gz
bitbake: bitbake: Convert to python 3
Various misc changes to convert bitbake to python3 which don't warrant separation into separate commits. (Bitbake rev: d0f904d407f57998419bd9c305ce53e5eaa36b24) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/process.py')
-rw-r--r--bitbake/lib/bb/process.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/bitbake/lib/bb/process.py b/bitbake/lib/bb/process.py
index 1c07f2d9b7..c62d7bca4f 100644
--- a/bitbake/lib/bb/process.py
+++ b/bitbake/lib/bb/process.py
@@ -17,7 +17,7 @@ class CmdError(RuntimeError):
17 self.msg = msg 17 self.msg = msg
18 18
19 def __str__(self): 19 def __str__(self):
20 if not isinstance(self.command, basestring): 20 if not isinstance(self.command, str):
21 cmd = subprocess.list2cmdline(self.command) 21 cmd = subprocess.list2cmdline(self.command)
22 else: 22 else:
23 cmd = self.command 23 cmd = self.command
@@ -97,6 +97,8 @@ def _logged_communicate(pipe, log, input, extrafiles):
97 try: 97 try:
98 while pipe.poll() is None: 98 while pipe.poll() is None:
99 rlist = rin 99 rlist = rin
100 stdoutbuf = b""
101 stderrbuf = b""
100 try: 102 try:
101 r,w,e = select.select (rlist, [], [], 1) 103 r,w,e = select.select (rlist, [], [], 1)
102 except OSError as e: 104 except OSError as e:
@@ -104,16 +106,26 @@ def _logged_communicate(pipe, log, input, extrafiles):
104 raise 106 raise
105 107
106 if pipe.stdout in r: 108 if pipe.stdout in r:
107 data = pipe.stdout.read() 109 data = stdoutbuf + pipe.stdout.read()
108 if data is not None: 110 if data is not None and len(data) > 0:
109 outdata.append(data) 111 try:
110 log.write(data) 112 data = data.decode("utf-8")
113 outdata.append(data)
114 log.write(data)
115 stdoutbuf = b""
116 except UnicodeDecodeError:
117 stdoutbuf = data
111 118
112 if pipe.stderr in r: 119 if pipe.stderr in r:
113 data = pipe.stderr.read() 120 data = stderrbuf + pipe.stderr.read()
114 if data is not None: 121 if data is not None and len(data) > 0:
115 errdata.append(data) 122 try:
116 log.write(data) 123 data = data.decode("utf-8")
124 errdata.append(data)
125 log.write(data)
126 stderrbuf = b""
127 except UnicodeDecodeError:
128 stderrbuf = data
117 129
118 readextras(r) 130 readextras(r)
119 131
@@ -135,7 +147,7 @@ def run(cmd, input=None, log=None, extrafiles=None, **options):
135 if not extrafiles: 147 if not extrafiles:
136 extrafiles = [] 148 extrafiles = []
137 149
138 if isinstance(cmd, basestring) and not "shell" in options: 150 if isinstance(cmd, str) and not "shell" in options:
139 options["shell"] = True 151 options["shell"] = True
140 152
141 try: 153 try:
@@ -150,6 +162,10 @@ def run(cmd, input=None, log=None, extrafiles=None, **options):
150 stdout, stderr = _logged_communicate(pipe, log, input, extrafiles) 162 stdout, stderr = _logged_communicate(pipe, log, input, extrafiles)
151 else: 163 else:
152 stdout, stderr = pipe.communicate(input) 164 stdout, stderr = pipe.communicate(input)
165 if stdout:
166 stdout = stdout.decode("utf-8")
167 if stderr:
168 stderr = stderr.decode("utf-8")
153 169
154 if pipe.returncode != 0: 170 if pipe.returncode != 0:
155 raise ExecutionError(cmd, pipe.returncode, stdout, stderr) 171 raise ExecutionError(cmd, pipe.returncode, stdout, stderr)