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