json.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """Create a keymap directory from a configurator export.
  2. """
  3. import json
  4. import os
  5. import sys
  6. import subprocess
  7. from milc import cli
  8. import qmk.keymap
  9. import qmk.path
  10. @cli.argument('filename', help='Configurator JSON export')
  11. @cli.entrypoint('Generate a keymap.c from a QMK Configurator export.')
  12. def main(cli):
  13. # Error checking
  14. if cli.args.filename == ('-'):
  15. cli.log.error('Reading from STDIN is not (yet) supported.')
  16. exit(1)
  17. if not os.path.exists(qmk.path.normpath(cli.args.filename)):
  18. cli.log.error('JSON file does not exist!')
  19. exit(1)
  20. # Parse the configurator json
  21. with open(qmk.path.normpath(cli.args.filename), 'r') as fd:
  22. user_keymap = json.load(fd)
  23. # Generate the keymap
  24. keymap_path = qmk.path.keymap(user_keymap['keyboard'])
  25. cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)
  26. qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers'])
  27. cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
  28. # Compile the keymap
  29. command = ['make', ':'.join((user_keymap['keyboard'], user_keymap['keymap']))]
  30. cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
  31. subprocess.run(command)