diff options
Diffstat (limited to 'lib/python/qmk/keyboard.py')
| -rw-r--r-- | lib/python/qmk/keyboard.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index e45768556..06c9df874 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py | |||
| @@ -6,10 +6,10 @@ from pathlib import Path | |||
| 6 | import os | 6 | import os |
| 7 | from glob import glob | 7 | from glob import glob |
| 8 | 8 | ||
| 9 | import qmk.path | ||
| 9 | from qmk.c_parse import parse_config_h_file | 10 | from qmk.c_parse import parse_config_h_file |
| 10 | from qmk.json_schema import json_load | 11 | from qmk.json_schema import json_load |
| 11 | from qmk.makefile import parse_rules_mk_file | 12 | from qmk.makefile import parse_rules_mk_file |
| 12 | from qmk.path import is_keyboard, under_qmk_firmware | ||
| 13 | 13 | ||
| 14 | BOX_DRAWING_CHARACTERS = { | 14 | BOX_DRAWING_CHARACTERS = { |
| 15 | "unicode": { | 15 | "unicode": { |
| @@ -36,7 +36,7 @@ base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep | |||
| 36 | def find_keyboard_from_dir(): | 36 | def find_keyboard_from_dir(): |
| 37 | """Returns a keyboard name based on the user's current directory. | 37 | """Returns a keyboard name based on the user's current directory. |
| 38 | """ | 38 | """ |
| 39 | relative_cwd = under_qmk_firmware() | 39 | relative_cwd = qmk.path.under_qmk_firmware() |
| 40 | 40 | ||
| 41 | if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards': | 41 | if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards': |
| 42 | # Attempt to extract the keyboard name from the current directory | 42 | # Attempt to extract the keyboard name from the current directory |
| @@ -47,10 +47,23 @@ def find_keyboard_from_dir(): | |||
| 47 | keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 | 47 | keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 |
| 48 | current_path = current_path.parents[keymap_index] | 48 | current_path = current_path.parents[keymap_index] |
| 49 | 49 | ||
| 50 | if is_keyboard(current_path): | 50 | if qmk.path.is_keyboard(current_path): |
| 51 | return str(current_path) | 51 | return str(current_path) |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | def find_readme(keyboard): | ||
| 55 | """Returns the readme for this keyboard. | ||
| 56 | """ | ||
| 57 | cur_dir = qmk.path.keyboard(keyboard) | ||
| 58 | keyboards_dir = Path('keyboards') | ||
| 59 | while not (cur_dir / 'readme.md').exists(): | ||
| 60 | if cur_dir == keyboards_dir: | ||
| 61 | return None | ||
| 62 | cur_dir = cur_dir.parent | ||
| 63 | |||
| 64 | return cur_dir / 'readme.md' | ||
| 65 | |||
| 66 | |||
| 54 | def keyboard_folder(keyboard): | 67 | def keyboard_folder(keyboard): |
| 55 | """Returns the actual keyboard folder. | 68 | """Returns the actual keyboard folder. |
| 56 | 69 | ||
| @@ -67,7 +80,7 @@ def keyboard_folder(keyboard): | |||
| 67 | rules_mk = parse_rules_mk_file(rules_mk_file) | 80 | rules_mk = parse_rules_mk_file(rules_mk_file) |
| 68 | keyboard = rules_mk.get('DEFAULT_FOLDER', keyboard) | 81 | keyboard = rules_mk.get('DEFAULT_FOLDER', keyboard) |
| 69 | 82 | ||
| 70 | if not is_keyboard(keyboard): | 83 | if not qmk.path.is_keyboard(keyboard): |
| 71 | raise ValueError(f'Invalid keyboard: {keyboard}') | 84 | raise ValueError(f'Invalid keyboard: {keyboard}') |
| 72 | 85 | ||
| 73 | return keyboard | 86 | return keyboard |
