@@ -673,23 +673,21 @@ class QemuRunner:
return (1, "")
raise Exception("No data on serial console socket, connection closed?")
- if data:
- if raw:
- status = 1
- else:
- # Remove first line (command line) and last line (prompt)
- data = data[data.find('$?\r\n')+4:data.rfind('\r\n')]
- index = data.rfind('\r\n')
- if index == -1:
- status_cmd = data
- data = ""
- else:
- status_cmd = data[index+2:]
- data = data[:index]
- if (status_cmd == "0"):
- status = 1
- return (status, str(data))
-
+ # If we got no data, we assume something went wrong and return 0
+ if not data:
+ return (0, str(None))
+
+ # in raw mode, we cannot check exit status output and thus assume success
+ if raw:
+ return (1, str(data))
+
+ # Split lines into array and remove first line (command line) and last line (prompt)
+ # Also remove empty lines to ease catching results
+ outlines = list(filter(None, data.splitlines()[1:-1]))
+ # Remaining last line contains exit code output
+ if (outlines[-1] == "0"):
+ status = 1
+ return (status, "\n".join(outlines[0:-1]))
def _dump_host(self):
self.host_dumper.create_dir("qemu")
Reduces the nesting depth and replaces the manual newline matching by built-in splitlines() method. This makes it compatible with shells that use windows-compatible line breaks, e.g. for EFI loaders. More comments and an early return handling should make the code a bit more readable. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> --- meta/lib/oeqa/utils/qemurunner.py | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-)