commands.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Functions that build make commands
  2. """
  3. import json
  4. import qmk.keymap
  5. def create_make_command(keyboard, keymap, target=None):
  6. """Create a make compile command
  7. Args:
  8. keyboard
  9. The path of the keyboard, for example 'plank'
  10. keymap
  11. The name of the keymap, for example 'algernon'
  12. target
  13. Usually a bootloader.
  14. Returns:
  15. A command that can be run to make the specified keyboard and keymap
  16. """
  17. if target is None:
  18. return ['make', ':'.join((keyboard, keymap))]
  19. return ['make', ':'.join((keyboard, keymap, target))]
  20. def parse_configurator_json(configurator_filename):
  21. """Open and parse a configurator json export
  22. """
  23. file = open(configurator_filename)
  24. user_keymap = json.load(file)
  25. file.close()
  26. return user_keymap
  27. def compile_configurator_json(configurator_filename, bootloader=None):
  28. """Convert a configurator export JSON file into a C file
  29. Args:
  30. configurator_filename
  31. The configurator JSON export file
  32. bootloader
  33. A bootloader to flash
  34. Returns:
  35. A command to run to compile and flash the C file.
  36. """
  37. # Parse the configurator json
  38. user_keymap = parse_configurator_json(configurator_filename)
  39. # Write the keymap C file
  40. qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers'])
  41. # Return a command that can be run to make the keymap and flash if given
  42. if bootloader is None:
  43. return create_make_command(user_keymap['keyboard'], user_keymap['keymap'])
  44. return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader)