diff options
| -rw-r--r-- | docs/cli.md | 4 | ||||
| -rw-r--r-- | lib/python/qmk/cli/list/keymaps.py | 11 | ||||
| -rw-r--r-- | lib/python/qmk/makefile.py | 2 | ||||
| -rw-r--r-- | lib/python/qmk/path.py | 23 | ||||
| -rw-r--r-- | requirements.txt | 1 |
5 files changed, 18 insertions, 23 deletions
diff --git a/docs/cli.md b/docs/cli.md index f2b433fbb..8ee8ab0e8 100644 --- a/docs/cli.md +++ b/docs/cli.md | |||
| @@ -252,14 +252,14 @@ This command lists all the keyboards currently defined in `qmk_firmware` | |||
| 252 | qmk list-keyboards | 252 | qmk list-keyboards |
| 253 | ``` | 253 | ``` |
| 254 | 254 | ||
| 255 | ## `qmk list_keymaps` | 255 | ## `qmk list-keymaps` |
| 256 | 256 | ||
| 257 | This command lists all the keymaps for a specified keyboard (and revision). | 257 | This command lists all the keymaps for a specified keyboard (and revision). |
| 258 | 258 | ||
| 259 | **Usage**: | 259 | **Usage**: |
| 260 | 260 | ||
| 261 | ``` | 261 | ``` |
| 262 | qmk list_keymaps -kb planck/ez | 262 | qmk list-keymaps -kb planck/ez |
| 263 | ``` | 263 | ``` |
| 264 | 264 | ||
| 265 | ## `qmk new-keymap` | 265 | ## `qmk new-keymap` |
diff --git a/lib/python/qmk/cli/list/keymaps.py b/lib/python/qmk/cli/list/keymaps.py index 494fe66a1..a17c6a913 100644 --- a/lib/python/qmk/cli/list/keymaps.py +++ b/lib/python/qmk/cli/list/keymaps.py | |||
| @@ -10,11 +10,14 @@ def list_keymaps(cli): | |||
| 10 | """List the keymaps for a specific keyboard | 10 | """List the keymaps for a specific keyboard |
| 11 | """ | 11 | """ |
| 12 | # ask for user input if keyboard was not provided in the command line | 12 | # ask for user input if keyboard was not provided in the command line |
| 13 | keyboard_name = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ") | 13 | if not cli.config.list_keymaps.keyboard: |
| 14 | cli.config.list_keymaps.keyboard = input("Keyboard Name: ") | ||
| 14 | 15 | ||
| 15 | try: | 16 | try: |
| 16 | for name in qmk.keymap.list_keymaps(keyboard_name): | 17 | for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard): |
| 17 | # We echo instead of cli.log.info to allow easier piping of this output | 18 | # We echo instead of cli.log.info to allow easier piping of this output |
| 18 | cli.echo(keyboard_name + ":" + name) | 19 | cli.echo('%s:%s', cli.config.list_keymaps.keyboard, name) |
| 19 | except NoSuchKeyboardError as e: | 20 | except NoSuchKeyboardError as e: |
| 20 | cli.echo("{fg_red}" + e.message) | 21 | cli.echo("{fg_red}%s: %s", cli.config.list_keymaps.keyboard, e.message) |
| 22 | except (FileNotFoundError, PermissionError) as e: | ||
| 23 | cli.echo("{fg_red}%s: %s", cli.config.list_keymaps.keyboard, e) | ||
diff --git a/lib/python/qmk/makefile.py b/lib/python/qmk/makefile.py index dc498adc8..6ed6b4b70 100644 --- a/lib/python/qmk/makefile.py +++ b/lib/python/qmk/makefile.py | |||
| @@ -21,8 +21,8 @@ def parse_rules_mk(file_path): | |||
| 21 | # group(2) = operator (eg.: '=', '+=') | 21 | # group(2) = operator (eg.: '=', '+=') |
| 22 | # group(3) = value(s) | 22 | # group(3) = value(s) |
| 23 | rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))") | 23 | rules_mk_regex = re.compile(r"^\s*(\w+)\s*([\?\:\+\-]?=)\s*(\S.*?)(?=\s*(\#|$))") |
| 24 | mk_content = qmk.path.unicode_lines(file_path) | ||
| 25 | parsed_file = dict() | 24 | parsed_file = dict() |
| 25 | mk_content = qmk.path.file_lines(file_path) | ||
| 26 | for line in mk_content: | 26 | for line in mk_content: |
| 27 | found = rules_mk_regex.search(line) | 27 | found = rules_mk_regex.search(line) |
| 28 | if found: | 28 | if found: |
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index e7e3ec53f..0cdfe353c 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py | |||
| @@ -5,8 +5,6 @@ import os | |||
| 5 | 5 | ||
| 6 | from qmk.errors import NoSuchKeyboardError | 6 | from qmk.errors import NoSuchKeyboardError |
| 7 | 7 | ||
| 8 | from bs4 import UnicodeDammit | ||
| 9 | |||
| 10 | def keymap(keyboard): | 8 | def keymap(keyboard): |
| 11 | """Locate the correct directory for storing a keymap. | 9 | """Locate the correct directory for storing a keymap. |
| 12 | 10 | ||
| @@ -35,19 +33,14 @@ def normpath(path): | |||
| 35 | 33 | ||
| 36 | return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path)) | 34 | return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path)) |
| 37 | 35 | ||
| 38 | def unicode_text(filename): | 36 | def file_lines(filename): |
| 39 | """Returns the contents of filename as a UTF-8 string. Tries to DTRT when it comes to encoding. | 37 | """ Return a files content, line by line |
| 40 | """ | ||
| 41 | with open(filename, "rb") as fd: | ||
| 42 | text = UnicodeDammit(fd.read()) | ||
| 43 | |||
| 44 | if text.contains_replacement_characters: | ||
| 45 | log_warning("%s: Could not determine file encoding, some characters were replaced." % (filename,)) | ||
| 46 | |||
| 47 | return text.unicode_markup or "" | ||
| 48 | 38 | ||
| 39 | Args: | ||
| 40 | filename: path to the file | ||
| 49 | 41 | ||
| 50 | def unicode_lines(filename): | 42 | Returns: |
| 51 | """Returns the contents of filename as a UTF-8 string. Tries to DTRT when it comes to encoding. | 43 | an list, in which each item is a line of the file |
| 52 | """ | 44 | """ |
| 53 | return unicode_text(filename).split("\n") | 45 | with open(filename, "r") as fd: |
| 46 | return fd.readlines() | ||
diff --git a/requirements.txt b/requirements.txt index bf4f411ed..074b11a8c 100644 --- a/requirements.txt +++ b/requirements.txt | |||
| @@ -7,4 +7,3 @@ hjson | |||
| 7 | nose2 | 7 | nose2 |
| 8 | flake8 | 8 | flake8 |
| 9 | pep8-naming | 9 | pep8-naming |
| 10 | bs4 | ||
