summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/new
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/cli/new
parent58724f8dcb9eccb1c132b8ddab422790ddd26be0 (diff)
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/cli/new')
-rwxr-xr-xlib/python/qmk/cli/new/keymap.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py
index 96525e28e1..cbe50692ec 100755
--- a/lib/python/qmk/cli/new/keymap.py
+++ b/lib/python/qmk/cli/new/keymap.py
@@ -1,8 +1,9 @@
"""This script automates the copying of the default keymap into your own keymap.
"""
-import os
import shutil
+from pathlib import Path
+import qmk.path
from milc import cli
@@ -17,24 +18,27 @@ def new_keymap(cli):
keymap = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else input("Keymap Name: ")
# generate keymap paths
- kb_path = os.path.join(os.getcwd(), "keyboards", keyboard)
- keymap_path_default = os.path.join(kb_path, "keymaps/default")
- keymap_path = os.path.join(kb_path, "keymaps/%s" % keymap)
+ kb_path = Path('keyboards') / keyboard
+ keymap_path = qmk.path.keymap(keyboard)
+ keymap_path_default = keymap_path / 'default'
+ keymap_path_new = keymap_path / keymap
# check directories
- if not os.path.exists(kb_path):
+ if not kb_path.exists():
cli.log.error('Keyboard %s does not exist!', kb_path)
exit(1)
- if not os.path.exists(keymap_path_default):
+
+ if not keymap_path_default.exists():
cli.log.error('Keyboard default %s does not exist!', keymap_path_default)
exit(1)
- if os.path.exists(keymap_path):
- cli.log.error('Keymap %s already exists!', keymap_path)
+
+ if keymap_path_new.exists():
+ cli.log.error('Keymap %s already exists!', keymap_path_new)
exit(1)
# create user directory with default keymap files
- shutil.copytree(keymap_path_default, keymap_path, symlinks=True)
+ shutil.copytree(str(keymap_path_default), str(keymap_path_new), symlinks=True)
# end message to user
- cli.log.info("%s keymap directory created in: %s", keymap, keymap_path)
- cli.log.info("Compile a firmware with your new keymap by typing: \n" + "qmk compile -kb %s -km %s", keyboard, keymap)
+ cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new)
+ cli.log.info("Compile a firmware with your new keymap by typing: \n\n\tqmk compile -kb %s -km %s\n", keyboard, keymap)