diff options
| author | Nick Brassel <nick@tzarc.org> | 2023-11-28 07:53:43 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-28 07:53:43 +1100 |
| commit | 5501e804ff8d41ce656061b91896c4ac8c681d78 (patch) | |
| tree | 6a655fbceaeab67cf727dbe4318721407dd31824 /lib/python/qmk/cli/userspace/list.py | |
| parent | 094357c40347e8a5db36578851f1af34a92e9f68 (diff) | |
QMK Userspace (#22222)
Co-authored-by: Duncan Sutherland <dunk2k_2000@hotmail.com>
Diffstat (limited to 'lib/python/qmk/cli/userspace/list.py')
| -rw-r--r-- | lib/python/qmk/cli/userspace/list.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/userspace/list.py b/lib/python/qmk/cli/userspace/list.py new file mode 100644 index 0000000000..a63f669dd7 --- /dev/null +++ b/lib/python/qmk/cli/userspace/list.py | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | # Copyright 2023 Nick Brassel (@tzarc) | ||
| 2 | # SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | from pathlib import Path | ||
| 4 | from dotty_dict import Dotty | ||
| 5 | from milc import cli | ||
| 6 | |||
| 7 | from qmk.constants import QMK_USERSPACE, HAS_QMK_USERSPACE | ||
| 8 | from qmk.userspace import UserspaceDefs | ||
| 9 | from qmk.build_targets import BuildTarget | ||
| 10 | from qmk.keyboard import is_all_keyboards, keyboard_folder | ||
| 11 | from qmk.keymap import is_keymap_target | ||
| 12 | from qmk.search import search_keymap_targets | ||
| 13 | |||
| 14 | |||
| 15 | @cli.argument('-e', '--expand', arg_only=True, action='store_true', help="Expands any use of `all` for either keyboard or keymap.") | ||
| 16 | @cli.subcommand('Lists the build targets specified in userspace `qmk.json`.') | ||
| 17 | def userspace_list(cli): | ||
| 18 | if not HAS_QMK_USERSPACE: | ||
| 19 | cli.log.error('Could not determine QMK userspace location. Please run `qmk doctor` or `qmk userspace-doctor` to diagnose.') | ||
| 20 | return False | ||
| 21 | |||
| 22 | userspace = UserspaceDefs(QMK_USERSPACE / 'qmk.json') | ||
| 23 | |||
| 24 | if cli.args.expand: | ||
| 25 | build_targets = [] | ||
| 26 | for e in userspace.build_targets: | ||
| 27 | if isinstance(e, Path): | ||
| 28 | build_targets.append(e) | ||
| 29 | elif isinstance(e, dict) or isinstance(e, Dotty): | ||
| 30 | build_targets.extend(search_keymap_targets([(e['keyboard'], e['keymap'])])) | ||
| 31 | else: | ||
| 32 | build_targets = userspace.build_targets | ||
| 33 | |||
| 34 | for e in build_targets: | ||
| 35 | if isinstance(e, Path): | ||
| 36 | # JSON keymap from userspace | ||
| 37 | cli.log.info(f'JSON keymap: {{fg_cyan}}{e}{{fg_reset}}') | ||
| 38 | continue | ||
| 39 | elif isinstance(e, dict) or isinstance(e, Dotty): | ||
| 40 | # keyboard/keymap dict from userspace | ||
| 41 | keyboard = e['keyboard'] | ||
| 42 | keymap = e['keymap'] | ||
| 43 | elif isinstance(e, BuildTarget): | ||
| 44 | # BuildTarget from search_keymap_targets() | ||
| 45 | keyboard = e.keyboard | ||
| 46 | keymap = e.keymap | ||
| 47 | |||
| 48 | if is_all_keyboards(keyboard) or is_keymap_target(keyboard_folder(keyboard), keymap): | ||
| 49 | cli.log.info(f'Keyboard: {{fg_cyan}}{keyboard}{{fg_reset}}, keymap: {{fg_cyan}}{keymap}{{fg_reset}}') | ||
| 50 | else: | ||
| 51 | cli.log.warn(f'Keyboard: {{fg_cyan}}{keyboard}{{fg_reset}}, keymap: {{fg_cyan}}{keymap}{{fg_reset}} -- not found!') | ||
