diff options
author | Zach White <skullydazed@gmail.com> | 2020-12-30 10:27:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-30 10:27:37 -0800 |
commit | 47b9b110097a864d6ab76516b2213afd59948527 (patch) | |
tree | 44c4e034c71b361af0cf865b735e09162bbc9656 /lib/python/qmk/cli/generate/info_json.py | |
parent | f231f24ddaac9781201a4ec9d0171c65af788839 (diff) | |
download | qmk_firmware-47b9b110097a864d6ab76516b2213afd59948527.tar.gz qmk_firmware-47b9b110097a864d6ab76516b2213afd59948527.zip |
Configure keyboard matrix from info.json (#10817)
* Make parameters from info.json available to the build system
* move all clueboard settings to info.json
* code formatting
* make flake8 happy
* make flake8 happy
* make qmk lint happy
* Add support for specifying led indicators in json
* move led indicators to the clueboard info.json
* Apply suggestions from code review
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
* add missing docstring
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk/cli/generate/info_json.py')
-rwxr-xr-x | lib/python/qmk/cli/generate/info_json.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/generate/info_json.py b/lib/python/qmk/cli/generate/info_json.py new file mode 100755 index 000000000..7e6654e45 --- /dev/null +++ b/lib/python/qmk/cli/generate/info_json.py | |||
@@ -0,0 +1,49 @@ | |||
1 | """Keyboard information script. | ||
2 | |||
3 | Compile an info.json for a particular keyboard and pretty-print it. | ||
4 | """ | ||
5 | import json | ||
6 | |||
7 | from milc import cli | ||
8 | |||
9 | from qmk.info_json_encoder import InfoJSONEncoder | ||
10 | from qmk.decorators import automagic_keyboard, automagic_keymap | ||
11 | from qmk.info import info_json | ||
12 | from qmk.path import is_keyboard | ||
13 | |||
14 | |||
15 | @cli.argument('-kb', '--keyboard', help='Keyboard to show info for.') | ||
16 | @cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') | ||
17 | @cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True) | ||
18 | @automagic_keyboard | ||
19 | @automagic_keymap | ||
20 | def generate_info_json(cli): | ||
21 | """Generate an info.json file for a keyboard | ||
22 | """ | ||
23 | # Determine our keyboard(s) | ||
24 | if not cli.config.generate_info_json.keyboard: | ||
25 | cli.log.error('Missing paramater: --keyboard') | ||
26 | cli.subcommands['info'].print_help() | ||
27 | return False | ||
28 | |||
29 | if not is_keyboard(cli.config.generate_info_json.keyboard): | ||
30 | cli.log.error('Invalid keyboard: "%s"', cli.config.generate_info_json.keyboard) | ||
31 | return False | ||
32 | |||
33 | # Build the info.json file | ||
34 | kb_info_json = info_json(cli.config.generate_info_json.keyboard) | ||
35 | pared_down_json = {} | ||
36 | |||
37 | for key in ('manufacturer', 'maintainer', 'usb', 'keyboard_name', 'width', 'height', 'debounce', 'diode_direction', 'features', 'community_layouts', 'layout_aliases', 'matrix_pins', 'rgblight', 'url'): | ||
38 | if key in kb_info_json: | ||
39 | pared_down_json[key] = kb_info_json[key] | ||
40 | |||
41 | pared_down_json['layouts'] = {} | ||
42 | if 'layouts' in pared_down_json: | ||
43 | for layout_name, layout in kb_info_json['layouts'].items(): | ||
44 | pared_down_json['layouts'][layout_name] = {} | ||
45 | pared_down_json['layouts'][layout_name]['key_count'] = layout.get('key_count', len(layout['layout'])) | ||
46 | pared_down_json['layouts'][layout_name]['layout'] = layout['layout'] | ||
47 | |||
48 | # Display the results | ||
49 | print(json.dumps(pared_down_json, indent=2, cls=InfoJSONEncoder)) | ||