Fix commandline parsing and flake8 findings, rebase

Fixed commandline and config parsing. Thx @xplusplus.
Rebased on master and fixed merge conflicts.
This commit is contained in:
Erovia 2020-01-07 21:54:21 +01:00 committed by skullydazed
parent 988bfffca2
commit 8eeab1112a
5 changed files with 18 additions and 5 deletions

View file

@ -4,13 +4,16 @@ from milc import cli
import qmk.keymap
from qmk.errors import NoSuchKeyboardError
@cli.argument("-kb", "--keyboard", help="Specify keyboard name. Example: 1upkeyboards/1up60hse")
@cli.subcommand("List the keymaps for a specific keyboard")
def list_keymaps(cli):
"""List the keymaps for a specific keyboard
"""
# ask for user input if keyboard was not provided in the command line
if not cli.config.list_keymaps.keyboard:
if cli.args.keyboard:
cli.config.list_keymaps.keyboard = cli.args.keyboard
elif not cli.config.list_keymaps.keyboard:
cli.config.list_keymaps.keyboard = input("Keyboard Name: ")
try:

View file

@ -1,11 +1,9 @@
"""Functions that help you work with QMK keymaps.
"""
import os
from traceback import format_exc
import qmk.path
import qmk.makefile
from qmk.errors import NoSuchKeyboardError
# The `keymap.c` template to use when a keyboard doesn't have its own
DEFAULT_KEYMAP_C = """#include QMK_KEYBOARD_H
@ -98,6 +96,7 @@ def write(keyboard, keymap, layout, layers):
return keymap_file
def list_keymaps(keyboard_name):
""" List the available keymaps for a keyboard.

View file

@ -5,6 +5,7 @@ import os
import qmk.path
from qmk.errors import NoSuchKeyboardError
def parse_rules_mk_file(file, rules_mk=None):
"""Turn a rules.mk file into a dictionary.
@ -45,12 +46,13 @@ def parse_rules_mk_file(file, rules_mk=None):
rules_mk[key.strip()] = value.strip()
else:
if ":=" in line:
line.replace(":","")
line.replace(":", "")
key, value = line.split('=', 1)
rules_mk[key.strip()] = value.strip()
return rules_mk
def get_rules_mk(keyboard):
""" Get a rules.mk for a keyboard

View file

@ -5,6 +5,7 @@ import os
from qmk.errors import NoSuchKeyboardError
def keymap(keyboard):
"""Locate the correct directory for storing a keymap.
@ -33,6 +34,7 @@ def normpath(path):
return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path))
def file_lines(filename):
""" Return a files content, line by line

View file

@ -55,7 +55,14 @@ def test_list_keyboards():
# this will fail if handwired/onekey/pytest is removed
assert 'handwired/onekey/pytest' in result.stdout
def test_list_keymaps():
result = check_subcommand("list_keymaps", "-kb", "planck/ez")
result = check_subcommand("list-keymaps", "-kb", "planck/ez")
assert result.returncode == 0
assert "planck/ez:default" and "planck/ez:drashna" in result.stdout
def test_list_keymaps_no_keyboard_found():
result = check_subcommand("list-keymaps", "-kb", "asdfghjkl")
assert result.returncode == 0
assert "does not exist" in result.stdout