aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/c2json.py22
-rwxr-xr-xlib/python/qmk/cli/json2c.py32
2 files changed, 27 insertions, 27 deletions
diff --git a/lib/python/qmk/cli/c2json.py b/lib/python/qmk/cli/c2json.py
index 8c8bd1f57..2b3bb774f 100644
--- a/lib/python/qmk/cli/c2json.py
+++ b/lib/python/qmk/cli/c2json.py
@@ -1,7 +1,6 @@
1"""Generate a keymap.json from a keymap.c file. 1"""Generate a keymap.json from a keymap.c file.
2""" 2"""
3import json 3import json
4import sys
5 4
6from milc import cli 5from milc import cli
7 6
@@ -21,19 +20,14 @@ def c2json(cli):
21 20
22 This command uses the `qmk.keymap` module to generate a keymap.json from a keymap.c file. The generated keymap is written to stdout, or to a file if -o is provided. 21 This command uses the `qmk.keymap` module to generate a keymap.json from a keymap.c file. The generated keymap is written to stdout, or to a file if -o is provided.
23 """ 22 """
24 cli.args.filename = qmk.path.normpath(cli.args.filename) 23 if cli.args.filename != '-':
24 cli.args.filename = qmk.path.normpath(cli.args.filename)
25 25
26 # Error checking 26 # Error checking
27 if not cli.args.filename.exists(): 27 if not cli.args.filename.exists():
28 cli.log.error('C file does not exist!') 28 cli.log.error('C file does not exist!')
29 cli.print_usage() 29 cli.print_usage()
30 exit(1) 30 return False
31
32 if str(cli.args.filename) == '-':
33 # TODO(skullydazed/anyone): Read file contents from STDIN
34 cli.log.error('Reading from STDIN is not (yet) supported.')
35 cli.print_usage()
36 exit(1)
37 31
38 # Environment processing 32 # Environment processing
39 if cli.args.output == ('-'): 33 if cli.args.output == ('-'):
@@ -47,7 +41,7 @@ def c2json(cli):
47 keymap_json = qmk.keymap.generate_json(keymap_json['keymap'], keymap_json['keyboard'], keymap_json['layout'], keymap_json['layers']) 41 keymap_json = qmk.keymap.generate_json(keymap_json['keymap'], keymap_json['keyboard'], keymap_json['layout'], keymap_json['layers'])
48 except KeyError: 42 except KeyError:
49 cli.log.error('Something went wrong. Try to use --no-cpp.') 43 cli.log.error('Something went wrong. Try to use --no-cpp.')
50 sys.exit(1) 44 return False
51 45
52 if cli.args.output: 46 if cli.args.output:
53 cli.args.output.parent.mkdir(parents=True, exist_ok=True) 47 cli.args.output.parent.mkdir(parents=True, exist_ok=True)
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