diff options
Diffstat (limited to 'lib/python/qmk/keymap.py')
-rw-r--r-- | lib/python/qmk/keymap.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 31c61ae6a..266532f50 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py | |||
@@ -3,6 +3,7 @@ | |||
3 | from pathlib import Path | 3 | from pathlib import Path |
4 | import json | 4 | import json |
5 | import subprocess | 5 | import subprocess |
6 | import sys | ||
6 | 7 | ||
7 | from pygments.lexers.c_cpp import CLexer | 8 | from pygments.lexers.c_cpp import CLexer |
8 | from pygments.token import Token | 9 | from pygments.token import Token |
@@ -312,16 +313,17 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa | |||
312 | return sorted(names) | 313 | return sorted(names) |
313 | 314 | ||
314 | 315 | ||
315 | def _c_preprocess(path): | 316 | def _c_preprocess(path, stdin=None): |
316 | """ Run a file through the C pre-processor | 317 | """ Run a file through the C pre-processor |
317 | 318 | ||
318 | Args: | 319 | Args: |
319 | path: path of the keymap.c file | 320 | path: path of the keymap.c file (set None to use stdin) |
321 | stdin: stdin pipe (e.g. sys.stdin) | ||
320 | 322 | ||
321 | Returns: | 323 | Returns: |
322 | the stdout of the pre-processor | 324 | the stdout of the pre-processor |
323 | """ | 325 | """ |
324 | pre_processed_keymap = qmk.commands.run(['cpp', path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | 326 | pre_processed_keymap = qmk.commands.run(['cpp', path] if path else ['cpp'], stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) |
325 | return pre_processed_keymap.stdout | 327 | return pre_processed_keymap.stdout |
326 | 328 | ||
327 | 329 | ||
@@ -451,17 +453,23 @@ def parse_keymap_c(keymap_file, use_cpp=True): | |||
451 | Currently only cares about the keymaps array. | 453 | Currently only cares about the keymaps array. |
452 | 454 | ||
453 | Args: | 455 | Args: |
454 | keymap_file: path of the keymap.c file | 456 | keymap_file: path of the keymap.c file (or '-' to use stdin) |
455 | 457 | ||
456 | use_cpp: if True, pre-process the file with the C pre-processor | 458 | use_cpp: if True, pre-process the file with the C pre-processor |
457 | 459 | ||
458 | Returns: | 460 | Returns: |
459 | a dictionary containing the parsed keymap | 461 | a dictionary containing the parsed keymap |
460 | """ | 462 | """ |
461 | if use_cpp: | 463 | if keymap_file == '-': |
462 | keymap_file = _c_preprocess(keymap_file) | 464 | if use_cpp: |
465 | keymap_file = _c_preprocess(None, sys.stdin) | ||
466 | else: | ||
467 | keymap_file = sys.stdin.read() | ||
463 | else: | 468 | else: |
464 | keymap_file = keymap_file.read_text() | 469 | if use_cpp: |
470 | keymap_file = _c_preprocess(keymap_file) | ||
471 | else: | ||
472 | keymap_file = keymap_file.read_text() | ||
465 | 473 | ||
466 | keymap = dict() | 474 | keymap = dict() |
467 | keymap['layers'] = _get_layers(keymap_file) | 475 | keymap['layers'] = _get_layers(keymap_file) |