aboutsummaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/qmk/cli/list/keymaps.py11
-rw-r--r--lib/python/qmk/makefile.py2
-rw-r--r--lib/python/qmk/path.py23
3 files changed, 16 insertions, 20 deletions
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
6from qmk.errors import NoSuchKeyboardError 6from qmk.errors import NoSuchKeyboardError
7 7
8from bs4 import UnicodeDammit
9
10def keymap(keyboard): 8def 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
38def unicode_text(filename): 36def 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
50def 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()