diff options
author | Zach White <skullydazed@gmail.com> | 2021-03-24 09:26:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-24 09:26:38 -0700 |
commit | 299008be36076343edadb7a36bf2fff820425ad1 (patch) | |
tree | d47d2fddc54b329b4ddb3128ef070b4cdba776a4 /lib/python/qmk/keyboard.py | |
parent | 723d9af04d610c4a2fcb8fcf39e8420c71ed4df0 (diff) |
Add support for qmk_configurator style aliases (#11954)
* Add support for qmk_configurator style aliases
* add the keyboard aliases to the api data
* add support for a keyboard metadata file
* make flake8 happy
Diffstat (limited to 'lib/python/qmk/keyboard.py')
-rw-r--r-- | lib/python/qmk/keyboard.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index a4c2873757..89f9346c40 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py @@ -7,7 +7,9 @@ import os from glob import glob from qmk.c_parse import parse_config_h_file +from qmk.json_schema import json_load from qmk.makefile import parse_rules_mk_file +from qmk.path import is_keyboard BOX_DRAWING_CHARACTERS = { "unicode": { @@ -31,6 +33,28 @@ BOX_DRAWING_CHARACTERS = { base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep +def keyboard_folder(keyboard): + """Returns the actual keyboard folder. + + This checks aliases and DEFAULT_FOLDER to resolve the actual path for a keyboard. + """ + aliases = json_load(Path('data/mappings/keyboard_aliases.json')) + + if keyboard in aliases: + keyboard = aliases[keyboard].get('target', keyboard) + + rules_mk_file = Path(base_path, keyboard, 'rules.mk') + + if rules_mk_file.exists(): + rules_mk = parse_rules_mk_file(rules_mk_file) + keyboard = rules_mk.get('DEFAULT_FOLDER', keyboard) + + if not is_keyboard(keyboard): + raise ValueError(f'Invalid keyboard: {keyboard}') + + return keyboard + + def _find_name(path): """Determine the keyboard name by stripping off the base_path and rules.mk. """ |