commands.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_file):
  21. """Open and parse a configurator json export
  22. """
  23. user_keymap = json.load(configurator_file)
  24. return user_keymap
  25. def compile_configurator_json(user_keymap, bootloader=None):
  26. """Convert a configurator export JSON file into a C file
  27. Args:
  28. configurator_filename
  29. The configurator JSON export file
  30. bootloader
  31. A bootloader to flash
  32. Returns:
  33. A command to run to compile and flash the C file.
  34. """
  35. # Write the keymap C file
  36. qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers'])
  37. # Return a command that can be run to make the keymap and flash if given
  38. if bootloader is None:
  39. return create_make_command(user_keymap['keyboard'], user_keymap['keymap'])
  40. return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader)