aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/json/keymap.py
diff options
context:
space:
mode:
authorskullydazed <skullydazed@users.noreply.github.com>2019-07-15 12:14:27 -0700
committerGitHub <noreply@github.com>2019-07-15 12:14:27 -0700
commita25dd58bc56b0c4010673723ac44eaff914979bb (patch)
treee4c08289df1b72db4ef8447ab7fdc13f604cffac /lib/python/qmk/cli/json/keymap.py
parent7ba82cb5b751d69dda6cc77ec8877c89defad3e4 (diff)
downloadqmk_firmware-a25dd58bc56b0c4010673723ac44eaff914979bb.tar.gz
qmk_firmware-a25dd58bc56b0c4010673723ac44eaff914979bb.zip
QMK CLI and JSON keymap support (#6176)
* Script to generate keymap.c from JSON file. * Support for keymap.json * Add a warning about the keymap.c getting overwritten. * Fix keymap generating * Install the python deps * Flesh out more of the python environment * Remove defunct json2keymap * Style everything with yapf * Polish up python support * Hide json keymap.c into the .build dir * Polish up qmk-compile-json * Make milc work with positional arguments * Fix a couple small things * Fix some errors and make the CLI more understandable * Make the qmk wrapper more robust * Add basic QMK Doctor * Clean up docstrings and flesh them out as needed * remove unused compile_firmware() function
Diffstat (limited to 'lib/python/qmk/cli/json/keymap.py')
-rwxr-xr-xlib/python/qmk/cli/json/keymap.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/json/keymap.py b/lib/python/qmk/cli/json/keymap.py
new file mode 100755
index 000000000..35fc8f9c0
--- /dev/null
+++ b/lib/python/qmk/cli/json/keymap.py
@@ -0,0 +1,54 @@
1"""Generate a keymap.c from a configurator export.
2"""
3import json
4import os
5import sys
6
7from milc import cli
8
9import qmk.keymap
10
11
12@cli.argument('-o', '--output', help='File to write to')
13@cli.argument('filename', help='Configurator JSON file')
14@cli.entrypoint('Create a keymap.c from a QMK Configurator export.')
15def main(cli):
16 """Generate a keymap.c from a configurator export.
17
18 This command uses the `qmk.keymap` module to generate a keymap.c from a configurator export. The generated keymap is written to stdout, or to a file if -o is provided.
19 """
20 # Error checking
21 if cli.args.filename == ('-'):
22 cli.log.error('Reading from STDIN is not (yet) supported.')
23 cli.print_usage()
24 exit(1)
25 if not os.path.exists(qmk.path.normpath(cli.args.filename)):
26 cli.log.error('JSON file does not exist!')
27 cli.print_usage()
28 exit(1)
29
30 # Environment processing
31 if cli.args.output == ('-'):
32 cli.args.output = None
33
34 # Parse the configurator json
35 with open(qmk.path.normpath(cli.args.filename), 'r') as fd:
36 user_keymap = json.load(fd)
37
38 # Generate the keymap
39 keymap_c = qmk.keymap.generate(user_keymap['keyboard'], user_keymap['layout'], user_keymap['layers'])
40
41 if cli.args.output:
42 output_dir = os.path.dirname(cli.args.output)
43
44 if not os.path.exists(output_dir):
45 os.makedirs(output_dir)
46
47 output_file = qmk.path.normpath(cli.args.output)
48 with open(output_file, 'w') as keymap_fd:
49 keymap_fd.write(keymap_c)
50
51 cli.log.info('Wrote keymap to %s.', cli.args.output)
52
53 else:
54 print(keymap_c)