summaryrefslogtreecommitdiff
path: root/lib/python/qmk/keymap.py
diff options
context:
space:
mode:
authorskullydazed <skullydazed@users.noreply.github.com>2020-02-17 11:42:11 -0800
committerGitHub <noreply@github.com>2020-02-17 11:42:11 -0800
commitc66930445f7d5941eb847568288046d51f853786 (patch)
tree273f290ca81a27bbbe7bdbf90221c02ac11f42cd /lib/python/qmk/keymap.py
parent58724f8dcb9eccb1c132b8ddab422790ddd26be0 (diff)
downloadqmk_firmware-c66930445f7d5941eb847568288046d51f853786.tar.gz
qmk_firmware-c66930445f7d5941eb847568288046d51f853786.zip
Use pathlib everywhere we can (#7872)
* Use pathlib everywhere we can * Update lib/python/qmk/path.py Co-Authored-By: Erovia <Erovia@users.noreply.github.com> * Update lib/python/qmk/path.py Co-Authored-By: Erovia <Erovia@users.noreply.github.com> * Improvements based on @erovia's feedback * rework qmk compile and qmk flash to use pathlib * style * Remove the subcommand_name argument from find_keyboard_keymap() Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk/keymap.py')
-rw-r--r--lib/python/qmk/keymap.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py
index 15a91a276b..b91ba89bed 100644
--- a/lib/python/qmk/keymap.py
+++ b/lib/python/qmk/keymap.py
@@ -31,11 +31,10 @@ def template(keyboard):
keyboard
The keyboard to return a template for.
"""
- template_name = 'keyboards/%s/templates/keymap.c' % keyboard
+ template_file = Path('keyboards/%s/templates/keymap.c' % keyboard)
- if os.path.exists(template_name):
- with open(template_name, 'r') as fd:
- return fd.read()
+ if template_file.exists():
+ return template_file.read_text()
return DEFAULT_KEYMAP_C
@@ -85,15 +84,10 @@ def write(keyboard, keymap, layout, layers):
An array of arrays describing the keymap. Each item in the inner array should be a string that is a valid QMK keycode.
"""
keymap_c = generate(keyboard, layout, layers)
- keymap_path = qmk.path.keymap(keyboard)
- keymap_dir = os.path.join(keymap_path, keymap)
- keymap_file = os.path.join(keymap_dir, 'keymap.c')
+ keymap_file = qmk.path.keymap(keyboard) / keymap / 'keymap.c'
- if not os.path.exists(keymap_dir):
- os.makedirs(keymap_dir)
-
- with open(keymap_file, 'w') as keymap_fd:
- keymap_fd.write(keymap_c)
+ keymap_file.parent.mkdir(parents=True, exist_ok=True)
+ keymap_file.write_text(keymap_c)
return keymap_file