Drop bs4 dependency, update docs, minor improvements

This commit is contained in:
Erovia 2019-10-24 20:33:58 +02:00 committed by skullydazed
parent d257a98cb8
commit 3ed1223678
5 changed files with 20 additions and 25 deletions

View File

@ -252,14 +252,14 @@ This command lists all the keyboards currently defined in `qmk_firmware`
qmk list-keyboards qmk list-keyboards
``` ```
## `qmk list_keymaps` ## `qmk list-keymaps`
This command lists all the keymaps for a specified keyboard (and revision). This command lists all the keymaps for a specified keyboard (and revision).
**Usage**: **Usage**:
``` ```
qmk list_keymaps -kb planck/ez qmk list-keymaps -kb planck/ez
``` ```
## `qmk new-keymap` ## `qmk new-keymap`

View File

@ -10,11 +10,14 @@ def list_keymaps(cli):
"""List the keymaps for a specific keyboard """List the keymaps for a specific keyboard
""" """
# ask for user input if keyboard was not provided in the command line # ask for user input if keyboard was not provided in the command line
keyboard_name = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") if not cli.config.list_keymaps.keyboard:
cli.config.list_keymaps.keyboard = input("Keyboard Name: ")
try: try:
for name in qmk.keymap.list_keymaps(keyboard_name): for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard):
# We echo instead of cli.log.info to allow easier piping of this output # We echo instead of cli.log.info to allow easier piping of this output
cli.echo(keyboard_name + ":" + name) cli.echo('%s:%s', cli.config.list_keymaps.keyboard, name)
except NoSuchKeyboardError as e: except NoSuchKeyboardError as e:
cli.echo("{fg_red}" + e.message) cli.echo("{fg_red}%s: %s", cli.config.list_keymaps.keyboard, e.message)
except (FileNotFoundError, PermissionError) as e:
cli.echo("{fg_red}%s: %s", cli.config.list_keymaps.keyboard, e)

View File

@ -21,8 +21,8 @@ def parse_rules_mk(file_path):
# group(2) = operator (eg.: '=', '+=') # group(2) = operator (eg.: '=', '+=')
# group(3) = value(s) # group(3) = value(s)
rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))") rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))")
mk_content = qmk.path.unicode_lines(file_path)
parsed_file = dict() parsed_file = dict()
mk_content = qmk.path.file_lines(file_path)
for line in mk_content: for line in mk_content:
found = rules_mk_regex.search(line) found = rules_mk_regex.search(line)
if found: if found:

View File

@ -5,8 +5,6 @@ import os
from qmk.errors import NoSuchKeyboardError from qmk.errors import NoSuchKeyboardError
from bs4 import UnicodeDammit
def keymap(keyboard): def keymap(keyboard):
"""Locate the correct directory for storing a keymap. """Locate the correct directory for storing a keymap.
@ -35,19 +33,14 @@ def normpath(path):
return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path)) return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path))
def unicode_text(filename): def file_lines(filename):
"""Returns the contents of filename as a UTF-8 string. Tries to DTRT when it comes to encoding. """ Return a files content, line by line
Args:
filename: path to the file
Returns:
an list, in which each item is a line of the file
""" """
with open(filename, "rb") as fd: with open(filename, "r") as fd:
text = UnicodeDammit(fd.read()) return fd.readlines()
if text.contains_replacement_characters:
log_warning("%s: Could not determine file encoding, some characters were replaced." % (filename,))
return text.unicode_markup or ""
def unicode_lines(filename):
"""Returns the contents of filename as a UTF-8 string. Tries to DTRT when it comes to encoding.
"""
return unicode_text(filename).split("\n")

View File

@ -7,4 +7,3 @@ hjson
nose2 nose2
flake8 flake8
pep8-naming pep8-naming
bs4