diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/python/qmk/cli/list/keymaps.py | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/lib/python/qmk/cli/list/keymaps.py b/lib/python/qmk/cli/list/keymaps.py index 709a5b9f9..d55ff91fc 100644 --- a/lib/python/qmk/cli/list/keymaps.py +++ b/lib/python/qmk/cli/list/keymaps.py | |||
| @@ -29,7 +29,7 @@ def parse_rules_mk(keyboard): | |||
| 29 | rules_mk_path_wildcard = os.path.join(base_path, "**", "rules.mk") | 29 | rules_mk_path_wildcard = os.path.join(base_path, "**", "rules.mk") |
| 30 | paths = [path for path in glob.iglob(rules_mk_path_wildcard, recursive=True) if "keymaps" not in path] | 30 | paths = [path for path in glob.iglob(rules_mk_path_wildcard, recursive=True) if "keymaps" not in path] |
| 31 | 31 | ||
| 32 | rules_mk = list() | 32 | rules_mk = dict() |
| 33 | for file in paths: | 33 | for file in paths: |
| 34 | rules_mk_content = unicode_lines(file) | 34 | rules_mk_content = unicode_lines(file) |
| 35 | parsed_file = dict() | 35 | parsed_file = dict() |
| @@ -37,9 +37,18 @@ def parse_rules_mk(keyboard): | |||
| 37 | found = re.search(r'^\s*(\w+)\s*=\s*((?:\s*\w+)+)', line) | 37 | found = re.search(r'^\s*(\w+)\s*=\s*((?:\s*\w+)+)', line) |
| 38 | if found: | 38 | if found: |
| 39 | parsed_file[found.group(1)] = found.group(2) | 39 | parsed_file[found.group(1)] = found.group(2) |
| 40 | rules_mk.append(parsed_file) | 40 | version = file.replace(base_path, "").replace(os.path.sep, "").replace("rules.mk", "") |
| 41 | rules_mk[version if version else "base"] = parsed_file | ||
| 41 | return rules_mk | 42 | return rules_mk |
| 42 | 43 | ||
| 44 | def find_keymaps(base_path, name_finder, community = False): | ||
| 45 | path_wildcard = os.path.join(base_path, "**", "keymap.c") | ||
| 46 | if community: | ||
| 47 | paths = [path for path in glob.iglob(path_wildcard, recursive=True)] | ||
| 48 | else: | ||
| 49 | paths = [path for path in glob.iglob(path_wildcard, recursive=True) if 'keymaps' in path] | ||
| 50 | return list(map(name_finder, paths)) | ||
| 51 | |||
| 43 | @cli.argument('-kb', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') | 52 | @cli.argument('-kb', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') |
| 44 | @cli.subcommand("List the keymaps for a specific keyboard") | 53 | @cli.subcommand("List the keymaps for a specific keyboard") |
| 45 | def list_keymaps(cli): | 54 | def list_keymaps(cli): |
| @@ -49,33 +58,21 @@ def list_keymaps(cli): | |||
| 49 | keyboard = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") | 58 | keyboard = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") |
| 50 | 59 | ||
| 51 | kb_base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep | 60 | kb_base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep |
| 52 | km_path_wildcard = os.path.join(kb_base_path, "**", "keymap.c") | ||
| 53 | |||
| 54 | # find everywhere we have rules.mk where keymaps isn't in the path | ||
| 55 | km_paths = [path for path in glob.iglob(km_path_wildcard, recursive=True) if 'keymaps' in path] | ||
| 56 | |||
| 57 | # replace the keyboard directory's path prefix with the keyboard's name and remove the keymap.c suffix | ||
| 58 | km_find_name = lambda path: path.replace(kb_base_path, keyboard + os.path.sep).replace("/keymaps/", ":").replace(os.path.sep + "keymap.c", "") | 61 | km_find_name = lambda path: path.replace(kb_base_path, keyboard + os.path.sep).replace("/keymaps/", ":").replace(os.path.sep + "keymap.c", "") |
| 59 | names = list(map(km_find_name, km_paths)) | 62 | names = find_keymaps(kb_base_path, km_find_name) |
| 60 | 63 | ||
| 61 | # get all the rules.mk files for the keyboard | 64 | # get all the rules.mk files for the keyboard |
| 62 | rules_mk = parse_rules_mk(keyboard) | 65 | rules_mk = parse_rules_mk(keyboard) |
| 63 | 66 | ||
| 64 | # find all the supported layouts | 67 | for version, data in rules_mk.items(): |
| 65 | all_supported_layouts = set() | 68 | if "LAYOUTS" in data: |
| 66 | for version in rules_mk: | 69 | if version == "base": |
| 67 | if "LAYOUTS" in version: | 70 | cl_find_name = lambda path: path.replace(cl_base_path, keyboard + ":").replace(os.path.sep + "keymap.c", "") |
| 68 | for layout in version["LAYOUTS"].split(): | 71 | else: |
| 69 | all_supported_layouts.add(layout) | 72 | cl_find_name = lambda path: path.replace(cl_base_path, keyboard + os.path.sep + version + ":").replace(os.path.sep + "keymap.c", "") |
| 70 | 73 | for layout in data["LAYOUTS"].split(): | |
| 71 | for layout in all_supported_layouts: | 74 | cl_base_path = os.path.join(os.getcwd(), "layouts", "community", layout) + os.path.sep |
| 72 | cl_base_path = os.path.join(os.getcwd(), "layouts", "community", layout) + os.path.sep | 75 | names = names + find_keymaps(cl_base_path, cl_find_name, community = True) |
| 73 | cl_path_wildcard = os.path.join(cl_base_path, "**", "keymap.c") | ||
| 74 | # find all the keymap.c files under the community layouts | ||
| 75 | cl_paths = [path for path in glob.iglob(cl_path_wildcard, recursive=True)] | ||
| 76 | # replace the community layouts directory's path with the keyboard's name and remove the keymap.c suffix | ||
| 77 | cl_find_name = lambda path: path.replace(cl_base_path, keyboard + ":").replace(os.path.sep + "keymap.c", "") | ||
| 78 | names = names + list(map(cl_find_name, cl_paths)) | ||
| 79 | 76 | ||
| 80 | names.sort() | 77 | names.sort() |
| 81 | 78 | ||
