toaster-eventreplay 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2014 Alex Damian
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-only
  6. #
  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. #
  10. """
  11. This command takes a filename as a single parameter. The filename is read
  12. as a build eventlog, and the ToasterUI is used to process events in the file
  13. and log data in the database
  14. """
  15. import os
  16. import sys
  17. import json
  18. import pickle
  19. import codecs
  20. import warnings
  21. warnings.simplefilter("default")
  22. from collections import namedtuple
  23. # mangle syspath to allow easy import of modules
  24. from os.path import join, dirname, abspath
  25. sys.path.insert(0, join(dirname(dirname(abspath(__file__))), 'lib'))
  26. import bb.cooker
  27. from bb.ui import toasterui
  28. from bb.ui import eventreplay
  29. def main(argv):
  30. with open(argv[-1]) as eventfile:
  31. # load variables from the first line
  32. variables = None
  33. while line := eventfile.readline().strip():
  34. try:
  35. variables = json.loads(line)['allvariables']
  36. break
  37. except (KeyError, json.JSONDecodeError):
  38. continue
  39. if not variables:
  40. sys.exit("Cannot find allvariables entry in event log file %s" % argv[-1])
  41. eventfile.seek(0)
  42. params = namedtuple('ConfigParams', ['observe_only'])(True)
  43. player = eventreplay.EventPlayer(eventfile, variables)
  44. return toasterui.main(player, player, params)
  45. # run toaster ui on our mock bitbake class
  46. if __name__ == "__main__":
  47. if len(sys.argv) != 2:
  48. print("Usage: %s <event file>" % os.path.basename(sys.argv[0]))
  49. sys.exit(1)
  50. sys.exit(main(sys.argv))