commands.py 1.5 KB

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