diff options
| author | Erovia <erovia@users.noreply.github.com> | 2019-10-10 22:58:52 +0200 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2020-02-15 15:19:03 -0800 |
| commit | e46cc2db8c4668b05ed873f57a54785ed56e2415 (patch) | |
| tree | 8f63c31bfb49af68ca4d20461bc2371680d932b4 /lib/python/qmk | |
| parent | c3b168e6fd8d414f95401dba471bdf6c12240d89 (diff) | |
| download | qmk_firmware-e46cc2db8c4668b05ed873f57a54785ed56e2415.tar.gz qmk_firmware-e46cc2db8c4668b05ed873f57a54785ed56e2415.zip | |
Try to figure out revision, drop -rv/--revision argument
Diffstat (limited to 'lib/python/qmk')
| -rw-r--r-- | lib/python/qmk/cli/list/keymaps.py | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/lib/python/qmk/cli/list/keymaps.py b/lib/python/qmk/cli/list/keymaps.py index 6cb21593f..f3a1f2a50 100644 --- a/lib/python/qmk/cli/list/keymaps.py +++ b/lib/python/qmk/cli/list/keymaps.py | |||
| @@ -26,61 +26,63 @@ def unicode_lines(filename): | |||
| 26 | 26 | ||
| 27 | def parse_rules_mk(keyboard, revision = ""): | 27 | def parse_rules_mk(keyboard, revision = ""): |
| 28 | base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep | 28 | base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep |
| 29 | rules_mk_path_wildcard = os.path.join(base_path, "**", "rules.mk") | ||
| 30 | rules_mk_regex = re.compile(r"^" + base_path + "(?:" + revision + os.path.sep + ")?rules.mk") | ||
| 31 | paths = [path for path in glob.iglob(rules_mk_path_wildcard, recursive = True) if rules_mk_regex.search(path)] | ||
| 32 | |||
| 33 | rules_mk = dict() | 29 | rules_mk = dict() |
| 34 | config_regex = re.compile(r"^\s*(\S+)\s*=\s*((?:\s*\S+)+)") | 30 | if os.path.exists(base_path + os.path.sep + revision): |
| 35 | for file_path in paths: | 31 | rules_mk_path_wildcard = os.path.join(base_path, "**", "rules.mk") |
| 36 | rules_mk_content = unicode_lines(file_path) | 32 | rules_mk_regex = re.compile(r"^" + base_path + "(?:" + revision + os.path.sep + ")?rules.mk") |
| 37 | parsed_file = dict() | 33 | paths = [path for path in glob.iglob(rules_mk_path_wildcard, recursive = True) if rules_mk_regex.search(path)] |
| 38 | for line in rules_mk_content: | 34 | |
| 39 | found = config_regex.search(line) | 35 | config_regex = re.compile(r"^\s*(\S+)\s*=\s*((?:\s*\S+)+)") |
| 40 | if found: | 36 | for file_path in paths: |
| 41 | parsed_file[found.group(1)] = found.group(2) | 37 | rules_mk_content = unicode_lines(file_path) |
| 42 | version = file_path.replace(base_path, "").replace(os.path.sep, "").replace("rules.mk", "") | 38 | parsed_file = dict() |
| 43 | rules_mk[version if version else "base"] = parsed_file | 39 | for line in rules_mk_content: |
| 40 | found = config_regex.search(line) | ||
| 41 | if found: | ||
| 42 | parsed_file[found.group(1)] = found.group(2) | ||
| 43 | version = file_path.replace(base_path, "").replace(os.path.sep, "").replace("rules.mk", "") | ||
| 44 | rules_mk[version if version else "base"] = parsed_file | ||
| 44 | return rules_mk | 45 | return rules_mk |
| 45 | 46 | ||
| 46 | def find_keymaps(base_path, revision = "", community = False): | 47 | def find_keymaps(base_path, revision = "", community = False): |
| 47 | path_wildcard = os.path.join(base_path, "**", "keymap.c") | 48 | path_wildcard = os.path.join(base_path, "**", "keymap.c") |
| 48 | if community: | 49 | if community: |
| 49 | path_regex = re.compile(r"^" + re.escape(base_path) + "(\S+)" + os.path.sep + "keymap\.c") | 50 | path_regex = re.compile(r"^" + re.escape(base_path) + "(\S+)" + os.path.sep + "keymap\.c") |
| 50 | names = [revision + os.path.sep + path_regex.sub(lambda name: name.group(1), path) for path in glob.iglob(path_wildcard, recursive = True)] | ||
| 51 | else: | 51 | else: |
| 52 | path_regex = re.compile(r"^" + re.escape(base_path) + "(?:" + re.escape(revision) + os.path.sep + ")?keymaps" + os.path.sep + "(\S+)" + os.path.sep + "keymap\.c") | 52 | path_regex = re.compile(r"^" + re.escape(base_path) + "(?:" + re.escape(revision) + os.path.sep + ")?keymaps" + os.path.sep + "(\S+)" + os.path.sep + "keymap\.c") |
| 53 | names = [revision + os.path.sep + path_regex.sub(lambda name: name.group(1), path) if revision else path_regex.sub(lambda name: name.group(1), path) for path in glob.iglob(path_wildcard, recursive = True) if path_regex.search(path)] | 53 | names = [path_regex.sub(lambda name: name.group(1), path) for path in glob.iglob(path_wildcard, recursive = True) if path_regex.search(path)] |
| 54 | return names | 54 | return names |
| 55 | 55 | ||
| 56 | @cli.argument("-kb", "--keyboard", help="Specify keyboard name. Example: 1upkeyboards/1up60hse") | 56 | @cli.argument("-kb", "--keyboard", help="Specify keyboard name. Example: 1upkeyboards/1up60hse") |
| 57 | @cli.argument("-rv", "--revision", help="Specify the revison name. Example: rev6") | ||
| 58 | @cli.subcommand("List the keymaps for a specific keyboard") | 57 | @cli.subcommand("List the keymaps for a specific keyboard") |
| 59 | def list_keymaps(cli): | 58 | def list_keymaps(cli): |
| 60 | """List the keymaps for a specific keyboard | 59 | """List the keymaps for a specific keyboard |
| 61 | """ | 60 | """ |
| 62 | # ask for user input if keyboard was not provided in the command line | 61 | # ask for user input if keyboard was not provided in the command line |
| 63 | keyboard = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") | 62 | keyboard_name = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") |
| 64 | revision = cli.config.list_keymaps.revision if cli.config.list_keymaps.revision else "" | 63 | if os.path.sep in keyboard_name: |
| 64 | keyboard, revision = os.path.split(os.path.normpath(keyboard_name)) | ||
| 65 | else: | ||
| 66 | keyboard = keyboard_name | ||
| 67 | revision = "" | ||
| 65 | 68 | ||
| 66 | # get all the rules.mk files for the keyboard | 69 | # get all the rules.mk files for the keyboard |
| 67 | rules_mk = parse_rules_mk(keyboard, revision) | 70 | rules_mk = parse_rules_mk(keyboard, revision) |
| 71 | names = list() | ||
| 68 | 72 | ||
| 69 | if "base" in rules_mk or revision: | 73 | if rules_mk: |
| 70 | keyboard_name = keyboard + os.path.sep + revision | 74 | if "base" in rules_mk or revision: |
| 71 | kb_base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep | 75 | kb_base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep |
| 72 | names = find_keymaps(kb_base_path, revision) | 76 | names = find_keymaps(kb_base_path, revision) |
| 73 | else: | ||
| 74 | names = list() | ||
| 75 | 77 | ||
| 76 | for rev, data in rules_mk.items(): | 78 | for rev, data in rules_mk.items(): |
| 77 | if "LAYOUTS" in data: | 79 | if "LAYOUTS" in data: |
| 78 | for layout in data["LAYOUTS"].split(): | 80 | for layout in data["LAYOUTS"].split(): |
| 79 | cl_base_path = os.path.join(os.getcwd(), "layouts", "community", layout) + os.path.sep | 81 | cl_base_path = os.path.join(os.getcwd(), "layouts", "community", layout) + os.path.sep |
| 80 | names = names + find_keymaps(cl_base_path, rev, community = True) | 82 | names = names + find_keymaps(cl_base_path, rev, community = True) |
| 81 | 83 | ||
| 82 | names.sort() | 84 | names.sort() |
| 83 | 85 | ||
| 84 | for name in names: | 86 | for name in names: |
| 85 | # We echo instead of cli.log.info to allow easier piping of this output | 87 | # We echo instead of cli.log.info to allow easier piping of this output |
| 86 | cli.echo(keyboard + os.path.sep + name) | 88 | cli.echo(keyboard_name + os.path.sep + name) |
