mpy_bin2res.py 497 B

123456789101112131415161718
  1. #!/usr/bin/env python3
  2. #
  3. # This tool converts binary resource files passed on the command line
  4. # into a Python source file containing data from these files, which can
  5. # be accessed using standard pkg_resources.resource_stream() function
  6. # from micropython-lib:
  7. # https://github.com/micropython/micropython-lib/tree/master/pkg_resources
  8. #
  9. import sys
  10. print("R = {")
  11. for fname in sys.argv[1:]:
  12. with open(fname, "rb") as f:
  13. b = f.read()
  14. print("%r: %r," % (fname, b))
  15. print("}")