[prev in list] [next in list] [prev in thread] [next in thread]
List: openembedded-core
Subject: [OE-core] [PATCH v2 5/9] oeqa/utils/qemurunner: simplify output parsing and make crlf-compatible
From: Enrico Jörns <ejo () pengutronix ! de>
Date: 2023-03-31 10:40:21
Message-ID: 20230331104025.1478393-6-ejo () pengutronix ! de
[Download RAW message or body]
Content-Transfer-Encoding: 8bit
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(-)
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 95c9e6596c..1e544acc90 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -672,23 +672,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 (#179423): https://lists.openembedded.org/g/openembedded-core/message/179423
Mute This Topic: https://lists.openembedded.org/mt/97970646/4454766
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [openembedded-core@marc.info]
-=-=-=-=-=-=-=-=-=-=-=-
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic