aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/json2c.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/json2c.py')
-rwxr-xr-xlib/python/qmk/cli/json2c.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/python/qmk/cli/json2c.py b/lib/python/qmk/cli/json2c.py
index 426078063..97d8fb0c3 100755
--- a/lib/python/qmk/cli/json2c.py
+++ b/lib/python/qmk/cli/json2c.py
@@ -1,6 +1,7 @@
1"""Generate a keymap.c from a configurator export. 1"""Generate a keymap.c from a configurator export.
2""" 2"""
3import json 3import json
4import sys
4 5
5from milc import cli 6from milc import cli
6 7
@@ -17,26 +18,31 @@ def json2c(cli):
17 18
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 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 """
20 # Error checking
21 if cli.args.filename and cli.args.filename.name == '-':
22 # TODO(skullydazed/anyone): Read file contents from STDIN
23 cli.log.error('Reading from STDIN is not (yet) supported.')
24 cli.print_usage()
25 return False
26 21
27 if not cli.args.filename.exists(): 22 try:
28 cli.log.error('JSON file does not exist!') 23 # Parse the configurator from stdin
29 cli.print_usage() 24 if cli.args.filename and cli.args.filename.name == '-':
25 user_keymap = json.load(sys.stdin)
26
27 else:
28 # Error checking
29 if not cli.args.filename.exists():
30 cli.log.error('JSON file does not exist!')
31 return False
32
33 # Parse the configurator json file
34 else:
35 user_keymap = json.loads(cli.args.filename.read_text())
36
37 except json.decoder.JSONDecodeError as ex:
38 cli.log.error('The JSON input does not appear to be valid.')
39 cli.log.error(ex)
30 return False 40 return False
31 41
32 # Environment processing 42 # Environment processing
33 if cli.args.output and cli.args.output.name == '-': 43 if cli.args.output and cli.args.output.name == '-':
34 cli.args.output = None 44 cli.args.output = None
35 45
36 # Parse the configurator json
37 with cli.args.filename.open('r') as fd:
38 user_keymap = json.load(fd)
39
40 # Generate the keymap 46 # Generate the keymap
41 keymap_c = qmk.keymap.generate_c(user_keymap['keyboard'], user_keymap['layout'], user_keymap['layers']) 47 keymap_c = qmk.keymap.generate_c(user_keymap['keyboard'], user_keymap['layout'], user_keymap['layers'])
42 48