diff options
author | Ryan <[email protected]> | 2023-05-19 16:05:43 +1000 |
---|---|---|
committer | GitHub <[email protected]> | 2023-05-19 16:05:43 +1000 |
commit | dc75c23f5c4768d48e6e77fb4e795ff0e0ee2d7f (patch) | |
tree | 2e2a2f07c1de1242afcabf888bf08b1db3379cac /lib/python/qmk/path.py | |
parent | 78afa1164dcae6b4acdac46d284850e6137fe41c (diff) | |
download | qmk_firmware-dc75c23f5c4768d48e6e77fb4e795ff0e0ee2d7f.tar.gz qmk_firmware-dc75c23f5c4768d48e6e77fb4e795ff0e0ee2d7f.zip |
CLI: Improve keymap folder resolution (#20981)
Diffstat (limited to 'lib/python/qmk/path.py')
-rw-r--r-- | lib/python/qmk/path.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 556d0eefc8..9d248451b8 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -36,8 +36,8 @@ def keyboard(keyboard_name): return Path('keyboards') / keyboard_name -def keymap(keyboard_name): - """Locate the correct directory for storing a keymap. +def keymaps(keyboard_name): + """Returns all of the `keymaps/` directories for a given keyboard. Args: @@ -45,17 +45,36 @@ def keymap(keyboard_name): The name of the keyboard. Example: clueboard/66/rev3 """ keyboard_folder = keyboard(keyboard_name) + found_dirs = [] for _ in range(MAX_KEYBOARD_SUBFOLDERS): if (keyboard_folder / 'keymaps').exists(): - return (keyboard_folder / 'keymaps').resolve() + found_dirs.append((keyboard_folder / 'keymaps').resolve()) keyboard_folder = keyboard_folder.parent + if len(found_dirs) > 0: + return found_dirs + logging.error('Could not find the keymaps directory!') raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard_name) +def keymap(keyboard_name, keymap_name): + """Locate the directory of a given keymap. + + Args: + + keyboard_name + The name of the keyboard. Example: clueboard/66/rev3 + keymap_name + The name of the keymap. Example: default + """ + for keymap_dir in keymaps(keyboard_name): + if (keymap_dir / keymap_name).exists(): + return (keymap_dir / keymap_name).resolve() + + def normpath(path): """Returns a `pathlib.Path()` object for a given path. |