keymap.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """This script automates the copying of the default keymap into your own keymap.
  2. """
  3. import shutil
  4. from pathlib import Path
  5. import qmk.path
  6. from qmk.decorators import automagic_keyboard, automagic_keymap
  7. from milc import cli
  8. @cli.argument('-kb', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse')
  9. @cli.argument('-km', '--keymap', help='Specify the name for the new keymap directory')
  10. @cli.subcommand('Creates a new keymap for the keyboard of your choosing')
  11. @automagic_keyboard
  12. @automagic_keymap
  13. def new_keymap(cli):
  14. """Creates a new keymap for the keyboard of your choosing.
  15. """
  16. # ask for user input if keyboard or keymap was not provided in the command line
  17. keyboard = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else input("Keyboard Name: ")
  18. keymap = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else input("Keymap Name: ")
  19. # generate keymap paths
  20. kb_path = Path('keyboards') / keyboard
  21. keymap_path = qmk.path.keymap(keyboard)
  22. keymap_path_default = keymap_path / 'default'
  23. keymap_path_new = keymap_path / keymap
  24. # check directories
  25. if not kb_path.exists():
  26. cli.log.error('Keyboard %s does not exist!', kb_path)
  27. return False
  28. if not keymap_path_default.exists():
  29. cli.log.error('Keyboard default %s does not exist!', keymap_path_default)
  30. return False
  31. if keymap_path_new.exists():
  32. cli.log.error('Keymap %s already exists!', keymap_path_new)
  33. return False
  34. # create user directory with default keymap files
  35. shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
  36. # end message to user
  37. cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new)
  38. cli.log.info("Compile a firmware with your new keymap by typing: \n\n\tqmk compile -kb %s -km %s\n", keyboard, keymap)