diff options
Diffstat (limited to 'lib/python/qmk/commands.py')
-rw-r--r-- | lib/python/qmk/commands.py | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index cdb8ee037..3d4ed1616 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py | |||
@@ -1,12 +1,8 @@ | |||
1 | """Helper functions for commands. | 1 | """Helper functions for commands. |
2 | """ | 2 | """ |
3 | import json | 3 | import json |
4 | from pathlib import Path | ||
5 | |||
6 | from milc import cli | ||
7 | 4 | ||
8 | import qmk.keymap | 5 | import qmk.keymap |
9 | from qmk.path import is_keyboard, is_keymap_dir, under_qmk_firmware | ||
10 | 6 | ||
11 | 7 | ||
12 | def create_make_command(keyboard, keymap, target=None): | 8 | def create_make_command(keyboard, keymap, target=None): |
@@ -59,71 +55,6 @@ def compile_configurator_json(user_keymap, bootloader=None): | |||
59 | return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader) | 55 | return create_make_command(user_keymap['keyboard'], user_keymap['keymap'], bootloader) |
60 | 56 | ||
61 | 57 | ||
62 | def find_keyboard_keymap(): | ||
63 | """Returns `(keyboard_name, keymap_name)` based on the user's current environment. | ||
64 | |||
65 | This determines the keyboard and keymap name using the following precedence order: | ||
66 | |||
67 | * Command line flags (--keyboard and --keymap) | ||
68 | * Current working directory | ||
69 | * `keyboards/<keyboard_name>` | ||
70 | * `keyboards/<keyboard_name>/keymaps/<keymap_name>` | ||
71 | * `layouts/**/<keymap_name>` | ||
72 | * `users/<keymap_name>` | ||
73 | * Configuration | ||
74 | * cli.config.<subcommand>.keyboard | ||
75 | * cli.config.<subcommand>.keymap | ||
76 | """ | ||
77 | # Check to make sure their copy of MILC supports config_source | ||
78 | if not hasattr(cli, 'config_source'): | ||
79 | cli.log.error("Your QMK CLI is out of date. Please upgrade using pip3 or your package manager.") | ||
80 | exit(1) | ||
81 | |||
82 | # State variables | ||
83 | relative_cwd = under_qmk_firmware() | ||
84 | keyboard_name = "" | ||
85 | keymap_name = "" | ||
86 | |||
87 | # If the keyboard or keymap are passed as arguments use that in preference to anything else | ||
88 | if cli.config_source[cli._entrypoint.__name__]['keyboard'] == 'argument': | ||
89 | keyboard_name = cli.config[cli._entrypoint.__name__]['keyboard'] | ||
90 | if cli.config_source[cli._entrypoint.__name__]['keymap'] == 'argument': | ||
91 | keymap_name = cli.config[cli._entrypoint.__name__]['keymap'] | ||
92 | |||
93 | if not keyboard_name or not keymap_name: | ||
94 | # If we don't have a keyboard_name and keymap_name from arguments try to derive one or both | ||
95 | if relative_cwd and relative_cwd.parts and relative_cwd.parts[0] == 'keyboards': | ||
96 | # Try to determine the keyboard and/or keymap name | ||
97 | current_path = Path('/'.join(relative_cwd.parts[1:])) | ||
98 | |||
99 | if current_path.parts[-2] == 'keymaps': | ||
100 | if not keymap_name: | ||
101 | keymap_name = current_path.parts[-1] | ||
102 | if not keyboard_name: | ||
103 | keyboard_name = '/'.join(current_path.parts[:-2]) | ||
104 | elif not keyboard_name and is_keyboard(current_path): | ||
105 | keyboard_name = str(current_path) | ||
106 | |||
107 | elif relative_cwd and relative_cwd.parts and relative_cwd.parts[0] == 'layouts': | ||
108 | # Try to determine the keymap name from the community layout | ||
109 | if is_keymap_dir(relative_cwd) and not keymap_name: | ||
110 | keymap_name = relative_cwd.name | ||
111 | |||
112 | elif relative_cwd and relative_cwd.parts and relative_cwd.parts[0] == 'users': | ||
113 | # Try to determine the keymap name based on which userspace they're in | ||
114 | if not keymap_name and len(relative_cwd.parts) > 1: | ||
115 | keymap_name = relative_cwd.parts[1] | ||
116 | |||
117 | # If we still don't have a keyboard and keymap check the config | ||
118 | if not keyboard_name and cli.config[cli._entrypoint.__name__]['keyboard']: | ||
119 | keyboard_name = cli.config[cli._entrypoint.__name__]['keyboard'] | ||
120 | |||
121 | if not keymap_name and cli.config[cli._entrypoint.__name__]['keymap']: | ||
122 | keymap_name = cli.config[cli._entrypoint.__name__]['keymap'] | ||
123 | |||
124 | return (keyboard_name, keymap_name) | ||
125 | |||
126 | |||
127 | def parse_configurator_json(configurator_file): | 58 | def parse_configurator_json(configurator_file): |
128 | """Open and parse a configurator json export | 59 | """Open and parse a configurator json export |
129 | """ | 60 | """ |