bitbake-dumpsig 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python3
  2. # bitbake-dumpsig
  3. # BitBake task signature dump utility
  4. #
  5. # Copyright (C) 2013 Intel Corporation
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import os
  20. import sys
  21. import warnings
  22. import optparse
  23. import logging
  24. import pickle
  25. sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
  26. import bb.siggen
  27. def logger_create(name, output=sys.stderr):
  28. logger = logging.getLogger(name)
  29. console = logging.StreamHandler(output)
  30. format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
  31. if output.isatty():
  32. format.enable_color()
  33. console.setFormatter(format)
  34. logger.addHandler(console)
  35. logger.setLevel(logging.INFO)
  36. return logger
  37. logger = logger_create('bitbake-dumpsig')
  38. parser = optparse.OptionParser(
  39. description = "Dumps siginfo/sigdata files written out by BitBake",
  40. usage = """
  41. %prog sigdatafile""")
  42. options, args = parser.parse_args(sys.argv)
  43. if len(args) == 1:
  44. parser.print_help()
  45. else:
  46. try:
  47. output = bb.siggen.dump_sigfile(args[1])
  48. except IOError as e:
  49. logger.error(str(e))
  50. sys.exit(1)
  51. except (pickle.UnpicklingError, EOFError):
  52. logger.error('Invalid signature data - ensure you are specifying a sigdata/siginfo file')
  53. sys.exit(1)
  54. if output:
  55. print('\n'.join(output))