From 595232ec989499d0ee0b8db0b55f6e8ca418c786 Mon Sep 17 00:00:00 2001 From: Kenny Hoang Date: Tue, 10 Sep 2019 08:14:25 -0400 Subject: 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 --- lib/python/qmk/cli/new/keymap.py | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 lib/python/qmk/cli/new/keymap.py (limited to 'lib/python/qmk/cli/new/keymap.py') diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py new file mode 100755 index 0000000000..b378e5ab43 --- /dev/null +++ b/lib/python/qmk/cli/new/keymap.py @@ -0,0 +1,41 @@ +"""This script automates the copying of the default keymap into your own keymap. +""" +import os +import shutil + +from milc import cli + + +@cli.argument('-k', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') +@cli.argument('-u', '--username', help='Specify any name for the new keymap directory') +@cli.entrypoint('Creates a new keymap for the keyboard of your choosing') +def main(cli): + """Creates a new keymap for the keyboard of your choosing. + """ + # ask for user input if keyboard or username was not provided in the command line + keyboard = cli.config.general.keyboard if cli.config.general.keyboard else input("Keyboard Name: ") + username = cli.config.general.username if cli.config.general.username else input("Username: ") + + # 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" % username) + + # check directories + if not os.path.exists(kb_path): + cli.log.error('Keyboard %s does not exist!', kb_path) + exit(1) + if not os.path.exists(keymap_path_default): + 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) + exit(1) + + # create user directory with default keymap files + shutil.copytree(keymap_path_default, keymap_path, symlinks=True) + + # end message to user + cli.log.info("%s keymap directory created in: %s\n" + + "Compile a firmware file with your new keymap by typing: \n" + + "qmk compile -kb %s -km %s", username, keymap_path, keyboard, username) -- cgit v1.2.3 From d569f0877155efc752994f8a21f5cf001f9d6ae6 Mon Sep 17 00:00:00 2001 From: skullydazed Date: Sun, 22 Sep 2019 13:25:33 -0700 Subject: Configuration system for CLI (#6708) * Rework how bin/qmk handles subcommands * qmk config wip * Code to show all configs * Fully working `qmk config` command * Mark some CLI arguments so they don't pollute the config file * Fleshed out config support, nicer subcommand support * sync with installable cli * pyformat * Add a test for subcommand_modules * Documentation for the `qmk config` command * split config_token on space so qmk config is more predictable * Rework how subcommands are imported * Document `arg_only` * Document deleting from CLI * Document how multiple operations work * Add cli config to the doc index * Add tests for the cli commands * Make running the tests more reliable * Be more selective about building all default keymaps * Update new-keymap to fit the new subcommand style * Add documentation about writing CLI scripts * Document new-keyboard * Update docs/cli_configuration.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Update docs/cli_development.md Co-Authored-By: noroadsleft <18669334+noroadsleft@users.noreply.github.com> * Address yan's comments. * Apply suggestions from code review suggestions from @noahfrederick Co-Authored-By: Noah Frederick * Apply suggestions from code review Co-Authored-By: Noah Frederick * Remove pip3 from the test runner --- lib/python/qmk/cli/new/keymap.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/python/qmk/cli/new/keymap.py') diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py index b378e5ab43..5efb81c93f 100755 --- a/lib/python/qmk/cli/new/keymap.py +++ b/lib/python/qmk/cli/new/keymap.py @@ -6,15 +6,15 @@ import shutil from milc import cli -@cli.argument('-k', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') -@cli.argument('-u', '--username', help='Specify any name for the new keymap directory') -@cli.entrypoint('Creates a new keymap for the keyboard of your choosing') -def main(cli): +@cli.argument('-kb', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') +@cli.argument('-km', '--keymap', help='Specify the name for the new keymap directory') +@cli.subcommand('Creates a new keymap for the keyboard of your choosing') +def new_keymap(cli): """Creates a new keymap for the keyboard of your choosing. """ # ask for user input if keyboard or username was not provided in the command line - keyboard = cli.config.general.keyboard if cli.config.general.keyboard else input("Keyboard Name: ") - username = cli.config.general.username if cli.config.general.username else input("Username: ") + keyboard = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else input("Keyboard Name: ") + 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) @@ -36,6 +36,5 @@ def main(cli): shutil.copytree(keymap_path_default, keymap_path, symlinks=True) # end message to user - cli.log.info("%s keymap directory created in: %s\n" + - "Compile a firmware file with your new keymap by typing: \n" + - "qmk compile -kb %s -km %s", username, keymap_path, keyboard, username) + cli.log.info("%s keymap directory created in: %s", username, keymap_path) + cli.log.info("Compile a firmware with your new keymap by typing: \n" + "qmk compile -kb %s -km %s", keyboard, username) -- cgit v1.2.3 From 78f01eef2e4586f59b56703d0a4f1a57a1af40a1 Mon Sep 17 00:00:00 2001 From: "St. John Johnson" Date: Sat, 5 Oct 2019 23:41:15 -0700 Subject: Use `keymap` instead of `username` variable for `qmk new_keymap` (#6885) Username is not defined and this causes `qmk new_keymap` to error. This appears to have originated from a partial update in https://github.com/qmk/qmk_firmware/pull/6708/files#diff-d5208bcbc79aa428556a743b6ff41086. This change completes the migration from `username` to `keymap` --- lib/python/qmk/cli/new/keymap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/python/qmk/cli/new/keymap.py') diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py index 5efb81c93f..96525e28e1 100755 --- a/lib/python/qmk/cli/new/keymap.py +++ b/lib/python/qmk/cli/new/keymap.py @@ -12,14 +12,14 @@ from milc import cli def new_keymap(cli): """Creates a new keymap for the keyboard of your choosing. """ - # ask for user input if keyboard or username was not provided in the command line + # ask for user input if keyboard or keymap was not provided in the command line keyboard = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else input("Keyboard Name: ") 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" % username) + keymap_path = os.path.join(kb_path, "keymaps/%s" % keymap) # check directories if not os.path.exists(kb_path): @@ -36,5 +36,5 @@ def new_keymap(cli): shutil.copytree(keymap_path_default, keymap_path, symlinks=True) # end message to user - cli.log.info("%s keymap directory created in: %s", username, keymap_path) - cli.log.info("Compile a firmware with your new keymap by typing: \n" + "qmk compile -kb %s -km %s", keyboard, username) + 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) -- cgit v1.2.3