keymap.py 1.7 KB

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