diff options
author | Kenny Hoang <kenny.hoang87@gmail.com> | 2019-09-10 08:14:25 -0400 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-09-10 05:14:25 -0700 |
commit | 595232ec989499d0ee0b8db0b55f6e8ca418c786 (patch) | |
tree | 094103690c89fda5f47aaa810fbb2b01ef0d2c08 /lib/python | |
parent | 2e521b509ce0c853b2e62d1d16e0117b900ab9c2 (diff) | |
download | qmk_firmware-595232ec989499d0ee0b8db0b55f6e8ca418c786.tar.gz qmk_firmware-595232ec989499d0ee0b8db0b55f6e8ca418c786.zip |
Created new_keymap.py, python version of new_keymap.sh (#6066)
* Created python version of new_keymap.sh: new_keymap.py
* Updated usage message
* Updated new_keymap.py to use python3.5+ syntax & be more similar to new_keyboard.sh
* Updated complete message
* Updated usage in argparser and removed incorrect usage_message
* Reverted the fstrings back to strings that use .format() & updated docstring convention
* Added helper to recursively cd .. until at qmk_firmware root directory
* Revert "Added helper to recursively cd .. until at qmk_firmware root directory"
This reverts commit 61a0ff3b25f91901287bec8d58eb51a1f126e2ad.
* Updated new_keymap.py to use printf-style format strings
* First draft lib/python/qmk/cli/new/keymap.py with milc
* Removed shebang & syspath appending lines
* Added optional args & resolved some cr comemnts
* Added a docstring and updated strings
Diffstat (limited to 'lib/python')
-rw-r--r-- | lib/python/qmk/cli/__init__.py | 0 | ||||
-rw-r--r-- | lib/python/qmk/cli/new/__init__.py | 0 | ||||
-rwxr-xr-x | lib/python/qmk/cli/new/keymap.py | 41 | ||||
-rw-r--r-- | lib/python/qmk/path.py | 3 |
4 files changed, 44 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/python/qmk/cli/__init__.py | |||
diff --git a/lib/python/qmk/cli/new/__init__.py b/lib/python/qmk/cli/new/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/lib/python/qmk/cli/new/__init__.py | |||
diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py new file mode 100755 index 000000000..b378e5ab4 --- /dev/null +++ b/lib/python/qmk/cli/new/keymap.py | |||
@@ -0,0 +1,41 @@ | |||
1 | """This script automates the copying of the default keymap into your own keymap. | ||
2 | """ | ||
3 | import os | ||
4 | import shutil | ||
5 | |||
6 | from milc import cli | ||
7 | |||
8 | |||
9 | @cli.argument('-k', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') | ||
10 | @cli.argument('-u', '--username', help='Specify any name for the new keymap directory') | ||
11 | @cli.entrypoint('Creates a new keymap for the keyboard of your choosing') | ||
12 | def main(cli): | ||
13 | """Creates a new keymap for the keyboard of your choosing. | ||
14 | """ | ||
15 | # ask for user input if keyboard or username was not provided in the command line | ||
16 | keyboard = cli.config.general.keyboard if cli.config.general.keyboard else input("Keyboard Name: ") | ||
17 | username = cli.config.general.username if cli.config.general.username else input("Username: ") | ||
18 | |||
19 | # generate keymap paths | ||
20 | kb_path = os.path.join(os.getcwd(), "keyboards", keyboard) | ||
21 | keymap_path_default = os.path.join(kb_path, "keymaps/default") | ||
22 | keymap_path = os.path.join(kb_path, "keymaps/%s" % username) | ||
23 | |||
24 | # check directories | ||
25 | if not os.path.exists(kb_path): | ||
26 | cli.log.error('Keyboard %s does not exist!', kb_path) | ||
27 | exit(1) | ||
28 | if not os.path.exists(keymap_path_default): | ||
29 | cli.log.error('Keyboard default %s does not exist!', keymap_path_default) | ||
30 | exit(1) | ||
31 | if os.path.exists(keymap_path): | ||
32 | cli.log.error('Keymap %s already exists!', keymap_path) | ||
33 | exit(1) | ||
34 | |||
35 | # create user directory with default keymap files | ||
36 | shutil.copytree(keymap_path_default, keymap_path, symlinks=True) | ||
37 | |||
38 | # end message to user | ||
39 | cli.log.info("%s keymap directory created in: %s\n" + | ||
40 | "Compile a firmware file with your new keymap by typing: \n" + | ||
41 | "qmk compile -kb %s -km %s", username, keymap_path, keyboard, username) | ||
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index f2a8346a5..cf087265f 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py | |||
@@ -1,7 +1,10 @@ | |||
1 | """Functions that help us work with files and folders. | 1 | """Functions that help us work with files and folders. |
2 | """ | 2 | """ |
3 | import logging | ||
3 | import os | 4 | import os |
4 | 5 | ||
6 | from qmk.errors import NoSuchKeyboardError | ||
7 | |||
5 | 8 | ||
6 | def keymap(keyboard): | 9 | def keymap(keyboard): |
7 | """Locate the correct directory for storing a keymap. | 10 | """Locate the correct directory for storing a keymap. |