Skip to content

Commit

Permalink
Add missing 'keymap' value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erovia committed Sep 11, 2020
1 parent 7052364 commit 1c25047
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/python/qmk/cli/c2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to')
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
@cli.argument('-kb', '--keyboard', arg_only=True, required=True, help='The keyboard\'s name')
@cli.argument('-km', '--keymap', arg_only=True, required=True, help='The keymap\'s name')
@cli.argument('filename', arg_only=True, help='keymap.c file')
@cli.subcommand('Creates a keymap.json from a keymap.c file.')
def c2json(cli):
Expand All @@ -39,11 +40,11 @@ def c2json(cli):
cli.args.output = None

# Parse the keymap.c
keymap_json = qmk.keymap.c2json(cli.args.keyboard, cli.args.filename, use_cpp=cli.args.no_cpp)
keymap_json = qmk.keymap.c2json(cli.args.keyboard, cli.args.keymap, cli.args.filename, use_cpp=cli.args.no_cpp)

# Generate the keymap.json
try:
keymap_json = qmk.keymap.generate(keymap_json['keyboard'], keymap_json['layout'], keymap_json['layers'], type='json')
keymap_json = qmk.keymap.generate(keymap_json['keyboard'], keymap_json['layout'], keymap_json['layers'], type='json', keymap=keymap_json['keymap'])
except KeyError:
cli.log.error('Something went wrong. Try to use --no-cpp.')
sys.exit(1)
Expand Down
8 changes: 6 additions & 2 deletions lib/python/qmk/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def is_keymap_dir(keymap):
return True


def generate(keyboard, layout, layers, type='c'):
def generate(keyboard, layout, layers, type='c', keymap=None):
"""Returns a `keymap.c` or `keymap.json` for the specified keyboard, layout, and layers.
Args:
Expand All @@ -94,6 +94,7 @@ def generate(keyboard, layout, layers, type='c'):
"""
new_keymap = template(keyboard, type)
if type == 'json':
new_keymap['keymap'] = keymap
new_keymap['layout'] = layout
new_keymap['layers'] = layers
else:
Expand Down Expand Up @@ -377,12 +378,14 @@ def parse_keymap_c(keymap_file, use_cpp=True):
return keymap


def c2json(keyboard, keymap_file, use_cpp=True):
def c2json(keyboard, keymap, keymap_file, use_cpp=True):
""" Convert keymap.c to keymap.json
Args:
keyboard: The name of the keyboard
keymap: The name of the keymap
layout: The LAYOUT macro this keymap uses.
keymap_file: path of the keymap.c file
Expand All @@ -404,4 +407,5 @@ def c2json(keyboard, keymap_file, use_cpp=True):
keymap_json['layers'].append(layer.pop('keycodes'))

keymap_json['keyboard'] = keyboard
keymap_json['keymap'] = keymap
return keymap_json
8 changes: 4 additions & 4 deletions lib/python/qmk/tests/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ def test_info_matrix_render():


def test_c2json():
result = check_subcommand("c2json", "-kb", "handwired/onekey/pytest", "keyboards/handwired/onekey/keymaps/default/keymap.c")
result = check_subcommand("c2json", "-kb", "handwired/onekey/pytest", "-km", "default", "keyboards/handwired/onekey/keymaps/default/keymap.c")
check_returncode(result)
assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "layout": "LAYOUT_ortho_1x1", "layers": [["KC_A"]]}'
assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT_ortho_1x1", "layers": [["KC_A"]]}'


def test_c2json_nocpp():
result = check_subcommand("c2json", "--no-cpp", "-kb", "handwired/onekey/pytest", "keyboards/handwired/onekey/keymaps/pytest_nocpp/keymap.c")
result = check_subcommand("c2json", "--no-cpp", "-kb", "handwired/onekey/pytest", "-km", "default", "keyboards/handwired/onekey/keymaps/pytest_nocpp/keymap.c")
check_returncode(result)
assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}'
assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}'
4 changes: 2 additions & 2 deletions lib/python/qmk/tests/test_qmk_keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_generate_onekey_pytest():


def test_generate_onekey_pytest_json():
templ = qmk.keymap.generate('handwired/onekey/pytest', 'LAYOUT', [['KC_A']], type='json')
assert templ == {"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "layout": "LAYOUT", "layers": [["KC_A"]]}
templ = qmk.keymap.generate('handwired/onekey/pytest', 'LAYOUT', [['KC_A']], type='json', keymap='default')
assert templ == {"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_A"]]}


def test_parse_keymap_c():
Expand Down

0 comments on commit 1c25047

Please sign in to comment.