diff options
author | skullydazed <skullydazed@users.noreply.github.com> | 2020-02-17 11:42:11 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 11:42:11 -0800 |
commit | c66930445f7d5941eb847568288046d51f853786 (patch) | |
tree | 273f290ca81a27bbbe7bdbf90221c02ac11f42cd /lib/python/qmk/keymap.py | |
parent | 58724f8dcb9eccb1c132b8ddab422790ddd26be0 (diff) | |
download | qmk_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.py | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 15a91a276..b91ba89be 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py | |||
@@ -31,11 +31,10 @@ def template(keyboard): | |||
31 | keyboard | 31 | keyboard |
32 | The keyboard to return a template for. | 32 | The keyboard to return a template for. |
33 | """ | 33 | """ |
34 | template_name = 'keyboards/%s/templates/keymap.c' % keyboard | 34 | template_file = Path('keyboards/%s/templates/keymap.c' % keyboard) |
35 | 35 | ||
36 | if os.path.exists(template_name): | 36 | if template_file.exists(): |
37 | with open(template_name, 'r') as fd: | 37 | return template_file.read_text() |
38 | return fd.read() | ||
39 | 38 | ||
40 | return DEFAULT_KEYMAP_C | 39 | return DEFAULT_KEYMAP_C |
41 | 40 | ||
@@ -85,15 +84,10 @@ def write(keyboard, keymap, layout, layers): | |||
85 | An array of arrays describing the keymap. Each item in the inner array should be a string that is a valid QMK keycode. | 84 | An array of arrays describing the keymap. Each item in the inner array should be a string that is a valid QMK keycode. |
86 | """ | 85 | """ |
87 | keymap_c = generate(keyboard, layout, layers) | 86 | keymap_c = generate(keyboard, layout, layers) |
88 | keymap_path = qmk.path.keymap(keyboard) | 87 | keymap_file = qmk.path.keymap(keyboard) / keymap / 'keymap.c' |
89 | keymap_dir = os.path.join(keymap_path, keymap) | ||
90 | keymap_file = os.path.join(keymap_dir, 'keymap.c') | ||
91 | 88 | ||
92 | if not os.path.exists(keymap_dir): | 89 | keymap_file.parent.mkdir(parents=True, exist_ok=True) |
93 | os.makedirs(keymap_dir) | 90 | keymap_file.write_text(keymap_c) |
94 | |||
95 | with open(keymap_file, 'w') as keymap_fd: | ||
96 | keymap_fd.write(keymap_c) | ||
97 | 91 | ||
98 | return keymap_file | 92 | return keymap_file |
99 | 93 | ||