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 <e...@pengutronix.de>
---
 meta/lib/oeqa/utils/qemurunner.py | 32 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/meta/lib/oeqa/utils/qemurunner.py 
b/meta/lib/oeqa/utils/qemurunner.py
index c3d8e9e815..b08226f05a 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -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")
-- 
2.39.2

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#180400): 
https://lists.openembedded.org/g/openembedded-core/message/180400
Mute This Topic: https://lists.openembedded.org/mt/98499559/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to