Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2014 Alex Damian |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # This file re-uses code spread throughout other Bitbake source files. |
| 8 | # As such, all other copyrights belong to their own right holders. |
| 9 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | """ |
| 12 | This command takes a filename as a single parameter. The filename is read |
| 13 | as a build eventlog, and the ToasterUI is used to process events in the file |
| 14 | and log data in the database |
| 15 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | import os |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 18 | import sys |
| 19 | import json |
| 20 | import pickle |
| 21 | import codecs |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 22 | import warnings |
| 23 | warnings.simplefilter("default") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 24 | |
| 25 | from collections import namedtuple |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | |
| 27 | # mangle syspath to allow easy import of modules |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | from os.path import join, dirname, abspath |
| 29 | sys.path.insert(0, join(dirname(dirname(abspath(__file__))), 'lib')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | |
| 31 | import bb.cooker |
| 32 | from bb.ui import toasterui |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 33 | from bb.ui import eventreplay |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 35 | def main(argv): |
| 36 | with open(argv[-1]) as eventfile: |
| 37 | # load variables from the first line |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 38 | variables = None |
| 39 | while line := eventfile.readline().strip(): |
| 40 | try: |
| 41 | variables = json.loads(line)['allvariables'] |
| 42 | break |
| 43 | except (KeyError, json.JSONDecodeError): |
| 44 | continue |
| 45 | if not variables: |
| 46 | sys.exit("Cannot find allvariables entry in event log file %s" % argv[-1]) |
| 47 | eventfile.seek(0) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 48 | params = namedtuple('ConfigParams', ['observe_only'])(True) |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 49 | player = eventreplay.EventPlayer(eventfile, variables) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | return toasterui.main(player, player, params) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | |
| 53 | # run toaster ui on our mock bitbake class |
| 54 | if __name__ == "__main__": |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 55 | if len(sys.argv) != 2: |
| 56 | print("Usage: %s <event file>" % os.path.basename(sys.argv[0])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | sys.exit(1) |
| 58 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 | sys.exit(main(sys.argv)) |