diff options
Diffstat (limited to 'lib/python/qmk/keymap.py')
-rw-r--r-- | lib/python/qmk/keymap.py | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 9dd043c4a8..b7138aa4a1 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -334,33 +334,6 @@ def write_json(keyboard, keymap, layout, layers, macros=None): return write_file(keymap_file, keymap_content) -def write(keymap_json): - """Generate the `keymap.c` and write it to disk. - - Returns the filename written to. - - `keymap_json` should be a dict with the following keys: - keyboard - The name of the keyboard - - keymap - The name of the keymap - - layout - The LAYOUT macro this keymap uses. - - layers - An array of arrays describing the keymap. Each item in the inner array should be a string that is a valid QMK keycode. - - macros - A list of macros for this keymap. - """ - keymap_content = generate_c(keymap_json) - keymap_file = qmk.path.keymaps(keymap_json['keyboard'])[0] / keymap_json['keymap'] / 'keymap.c' - - return write_file(keymap_file, keymap_content) - - def locate_keymap(keyboard, keymap, force_layout=None): """Returns the path to a keymap for a specific keyboard. """ @@ -426,7 +399,7 @@ def is_keymap_target(keyboard, keymap): return False -def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False): +def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False, include_userspace=True): """List the available keymaps for a keyboard. Args: @@ -445,14 +418,19 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa fullpath When set to True the full path of the keymap relative to the `qmk_firmware` root will be provided. + include_userspace + When set to True, also search userspace for available keymaps + Returns: a sorted list of valid keymap names. """ names = set() + has_userspace = HAS_QMK_USERSPACE and include_userspace + # walk up the directory tree until keyboards_dir # and collect all directories' name with keymap.c file in it - for search_dir in [QMK_FIRMWARE, QMK_USERSPACE] if HAS_QMK_USERSPACE else [QMK_FIRMWARE]: + for search_dir in [QMK_FIRMWARE, QMK_USERSPACE] if has_userspace else [QMK_FIRMWARE]: keyboards_dir = search_dir / Path('keyboards') kb_path = keyboards_dir / keyboard @@ -470,7 +448,7 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa info = info_json(keyboard) community_parents = list(Path('layouts').glob('*/')) - if HAS_QMK_USERSPACE and (Path(QMK_USERSPACE) / "layouts").exists(): + if has_userspace and (Path(QMK_USERSPACE) / "layouts").exists(): community_parents.append(Path(QMK_USERSPACE) / "layouts") for community_parent in community_parents: |