2019-09-10 14:14:25 +02:00
|
|
|
"""This script automates the copying of the default keymap into your own keymap.
|
|
|
|
"""
|
|
|
|
import shutil
|
2020-02-17 20:42:11 +01:00
|
|
|
from pathlib import Path
|
2019-09-10 14:14:25 +02:00
|
|
|
|
2020-02-17 20:42:11 +01:00
|
|
|
import qmk.path
|
2020-03-13 23:47:04 +01:00
|
|
|
from qmk.decorators import automagic_keyboard, automagic_keymap
|
2019-09-10 14:14:25 +02:00
|
|
|
from milc import cli
|
|
|
|
|
|
|
|
|
2019-09-22 22:25:33 +02:00
|
|
|
@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')
|
2020-03-13 23:47:04 +01:00
|
|
|
@automagic_keyboard
|
|
|
|
@automagic_keymap
|
2019-09-22 22:25:33 +02:00
|
|
|
def new_keymap(cli):
|
2019-09-10 14:14:25 +02:00
|
|
|
"""Creates a new keymap for the keyboard of your choosing.
|
|
|
|
"""
|
2019-10-06 08:41:15 +02:00
|
|
|
# ask for user input if keyboard or keymap was not provided in the command line
|
2019-09-22 22:25:33 +02:00
|
|
|
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: ")
|
2019-09-10 14:14:25 +02:00
|
|
|
|
|
|
|
# generate keymap paths
|
2020-02-17 20:42:11 +01:00
|
|
|
kb_path = Path('keyboards') / keyboard
|
|
|
|
keymap_path = qmk.path.keymap(keyboard)
|
|
|
|
keymap_path_default = keymap_path / 'default'
|
|
|
|
keymap_path_new = keymap_path / keymap
|
2019-09-10 14:14:25 +02:00
|
|
|
|
|
|
|
# check directories
|
2020-02-17 20:42:11 +01:00
|
|
|
if not kb_path.exists():
|
2019-09-10 14:14:25 +02:00
|
|
|
cli.log.error('Keyboard %s does not exist!', kb_path)
|
|
|
|
exit(1)
|
2020-02-17 20:42:11 +01:00
|
|
|
|
|
|
|
if not keymap_path_default.exists():
|
2019-09-10 14:14:25 +02:00
|
|
|
cli.log.error('Keyboard default %s does not exist!', keymap_path_default)
|
|
|
|
exit(1)
|
2020-02-17 20:42:11 +01:00
|
|
|
|
|
|
|
if keymap_path_new.exists():
|
|
|
|
cli.log.error('Keymap %s already exists!', keymap_path_new)
|
2019-09-10 14:14:25 +02:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# create user directory with default keymap files
|
2020-04-18 22:00:56 +02:00
|
|
|
shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
|
2019-09-10 14:14:25 +02:00
|
|
|
|
|
|
|
# end message to user
|
2020-02-17 20:42:11 +01:00
|
|
|
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)
|