diff mbox series

toaster-eventreplay: Remove ordering assumptions

Message ID 20231206224619.1703343-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit a833a403a8f7c05008108f3ec1710c211cfa9ec2
Headers show
Series toaster-eventreplay: Remove ordering assumptions | expand

Commit Message

Richard Purdie Dec. 6, 2023, 10:46 p.m. UTC
Currently the script assumes the variarables are dumped at the start of the
file which is hard to arrange safely in the bitbake code and no longer a true
assumption.

Rewrite the code so that it can cope with different ordering and event files
containing multiple builds.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 bin/toaster-eventreplay | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bin/toaster-eventreplay b/bin/toaster-eventreplay
index 404b61f516..f137c71d5c 100755
--- a/bin/toaster-eventreplay
+++ b/bin/toaster-eventreplay
@@ -45,7 +45,13 @@  class EventPlayer:
         if not line:
             return
         try:
-            event_str = json.loads(line)['vars'].encode('utf-8')
+            decodedline = json.loads(line)
+            if 'allvariables' in decodedline:
+                self.variables = decodedline['allvariables']
+                return
+            if not 'vars' in decodedline:
+                raise ValueError
+            event_str = decodedline['vars'].encode('utf-8')
             event = pickle.loads(codecs.decode(event_str, 'base64'))
             event_name = "%s.%s" % (event.__module__, event.__class__.__name__)
             if event_name not in self.eventmask:
@@ -99,8 +105,16 @@  class EventPlayer:
 def main(argv):
     with open(argv[-1]) as eventfile:
         # load variables from the first line
-        variables = json.loads(eventfile.readline().strip())['allvariables']
-
+        variables = None
+        while line := eventfile.readline().strip():
+            try:
+                variables = json.loads(line)['allvariables']
+                break
+            except (KeyError, json.JSONDecodeError):
+                continue
+        if not variables:
+            sys.exit("Cannot find allvariables entry in event log file %s" % argv[-1])
+        eventfile.seek(0)
         params = namedtuple('ConfigParams', ['observe_only'])(True)
         player = EventPlayer(eventfile, variables)