keyboards.py 878 B

123456789101112131415161718192021222324252627
  1. """List the keyboards currently defined within QMK
  2. """
  3. import os
  4. import glob
  5. from milc import cli
  6. BASE_PATH = os.path.join(os.getcwd(), "keyboards") + os.path.sep
  7. KB_WILDCARD = os.path.join(BASE_PATH, "**", "rules.mk")
  8. def find_name(path):
  9. """Determine the keyboard name by stripping off the base_path and rules.mk.
  10. """
  11. return path.replace(BASE_PATH, "").replace(os.path.sep + "rules.mk", "")
  12. @cli.subcommand("List the keyboards currently defined within QMK")
  13. def list_keyboards(cli):
  14. """List the keyboards currently defined within QMK
  15. """
  16. # find everywhere we have rules.mk where keymaps isn't in the path
  17. paths = [path for path in glob.iglob(KB_WILDCARD, recursive=True) if 'keymaps' not in path]
  18. # Extract the keyboard name from the path and print it
  19. for keyboard_name in sorted(map(find_name, paths)):
  20. print(keyboard_name)