From c66930445f7d5941eb847568288046d51f853786 Mon Sep 17 00:00:00 2001 From: skullydazed Date: Mon, 17 Feb 2020 11:42:11 -0800 Subject: Use pathlib everywhere we can (#7872) * Use pathlib everywhere we can * Update lib/python/qmk/path.py Co-Authored-By: Erovia * Update lib/python/qmk/path.py Co-Authored-By: Erovia * 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 --- lib/python/qmk/cli/new/keymap.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/python/qmk/cli/new') 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) -- cgit v1.2.3