diff options
author | Erovia <Erovia@users.noreply.github.com> | 2022-02-14 11:02:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-14 12:02:35 +0100 |
commit | 23c238a1807c3e8c3bdd4eb432506a1469640df5 (patch) | |
tree | 2c19237d83d1a237561d7d740910886f54b14c3f /lib | |
parent | 1980e48e0d9a5745291829e7612628cc24668c57 (diff) |
CLI: Minor additions #12795 (#16276)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/python/qmk/cli/new/keyboard.py | 89 | ||||
-rw-r--r-- | lib/python/qmk/constants.py | 39 |
2 files changed, 76 insertions, 52 deletions
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py index 59e781a932..8596994d38 100644 --- a/lib/python/qmk/cli/new/keyboard.py +++ b/lib/python/qmk/cli/new/keyboard.py @@ -15,48 +15,11 @@ from qmk.json_schema import load_jsonschema from qmk.path import keyboard from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import deep_update +from qmk.constants import MCU2BOOTLOADER COMMUNITY = Path('layouts/default/') TEMPLATE = Path('data/templates/keyboard/') -MCU2BOOTLOADER = { - "MKL26Z64": "halfkay", - "MK20DX128": "halfkay", - "MK20DX256": "halfkay", - "MK66FX1M0": "halfkay", - "STM32F042": "stm32-dfu", - "STM32F072": "stm32-dfu", - "STM32F103": "stm32duino", - "STM32F303": "stm32-dfu", - "STM32F401": "stm32-dfu", - "STM32F405": "stm32-dfu", - "STM32F407": "stm32-dfu", - "STM32F411": "stm32-dfu", - "STM32F446": "stm32-dfu", - "STM32G431": "stm32-dfu", - "STM32G474": "stm32-dfu", - "STM32L412": "stm32-dfu", - "STM32L422": "stm32-dfu", - "STM32L432": "stm32-dfu", - "STM32L433": "stm32-dfu", - "STM32L442": "stm32-dfu", - "STM32L443": "stm32-dfu", - "GD32VF103": "gd32v-dfu", - "WB32F3G71": "wb32-dfu", - "atmega16u2": "atmel-dfu", - "atmega32u2": "atmel-dfu", - "atmega16u4": "atmel-dfu", - "atmega32u4": "atmel-dfu", - "at90usb162": "atmel-dfu", - "at90usb646": "atmel-dfu", - "at90usb647": "atmel-dfu", - "at90usb1286": "atmel-dfu", - "at90usb1287": "atmel-dfu", - "atmega32a": "bootloadhid", - "atmega328p": "usbasploader", - "atmega328": "usbasploader", -} - # defaults schema = dotty(load_jsonschema('keyboard')) mcu_types = sorted(schema["properties.processor.enum"], key=str.casefold) @@ -141,20 +104,42 @@ def augment_community_info(src, dest): dest.write_text(json.dumps(info, cls=InfoJSONEncoder)) +def _question(*args, **kwargs): + """Ugly workaround until 'milc' learns to display a repromt msg + """ + # TODO: Remove this once milc.questions.question handles reprompt messages + + reprompt = kwargs["reprompt"] + del kwargs["reprompt"] + validate = kwargs["validate"] + del kwargs["validate"] + + prompt = args[0] + ret = None + while not ret: + ret = question(prompt, **kwargs) + if not validate(ret): + ret = None + prompt = reprompt + + return ret + + def prompt_keyboard(): prompt = """{fg_yellow}Name Your Keyboard Project{style_reset_all} - For more infomation, see: https://docs.qmk.fm/#/hardware_keyboard_guidelines?id=naming-your-keyboardproject -keyboard Name? """ +Keyboard Name? """ - return question(prompt, validate=lambda x: not keyboard(x).exists()) + errmsg = 'Keyboard already exists! Please choose a different name:' + return _question(prompt, reprompt=errmsg, validate=lambda x: not keyboard(x).exists()) -def prompt_user(): - prompt = """{fg_yellow}Attribution{style_reset_all} +def prompt_user(): + prompt = """ +{fg_yellow}Attribution{style_reset_all} Used for maintainer, copyright, etc Your GitHub Username? """ @@ -162,8 +147,8 @@ Your GitHub Username? """ def prompt_name(def_name): - prompt = """{fg_yellow}More Attribution{style_reset_all} - + prompt = """ +{fg_yellow}More Attribution{style_reset_all} Used for maintainer, copyright, etc Your Real Name? """ @@ -171,8 +156,8 @@ Your Real Name? """ def prompt_layout(): - prompt = """{fg_yellow}Pick Base Layout{style_reset_all} - + prompt = """ +{fg_yellow}Pick Base Layout{style_reset_all} As a starting point, one of the common layouts can be used to bootstrap the process Default Layout? """ @@ -184,8 +169,8 @@ Default Layout? """ def prompt_mcu(): - prompt = """{fg_yellow}What Powers Your Project{style_reset_all} - + prompt = """ +{fg_yellow}What Powers Your Project{style_reset_all} For more infomation, see: https://docs.qmk.fm/#/compatible_microcontrollers @@ -199,7 +184,7 @@ MCU? """ @cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name) @cli.argument('-l', '--layout', help='Community layout to bootstrap with', arg_only=True, type=layout_type) @cli.argument('-t', '--type', help='Specify the keyboard MCU type', arg_only=True, type=mcu_type) -@cli.argument('-u', '--username', help='Specify your username (default from Git config)', arg_only=True) +@cli.argument('-u', '--username', help='Specify your username (default from Git config)', dest='name') @cli.argument('-n', '--realname', help='Specify your real name if you want to use that. Defaults to username', arg_only=True) @cli.subcommand('Creates a new keyboard directory') def new_keyboard(cli): @@ -209,8 +194,8 @@ def new_keyboard(cli): cli.echo('') kb_name = cli.args.keyboard if cli.args.keyboard else prompt_keyboard() - user_name = cli.args.username if cli.args.username else prompt_user() - real_name = cli.args.realname or cli.args.username if cli.args.realname or cli.args.username else prompt_name(user_name) + user_name = cli.config.new_keyboard.name if cli.config.new_keyboard.name else prompt_user() + real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name) default_layout = cli.args.layout if cli.args.layout else prompt_layout() mcu = cli.args.type if cli.args.type else prompt_mcu() bootloader = select_default_bootloader(mcu) diff --git a/lib/python/qmk/constants.py b/lib/python/qmk/constants.py index 00e453189f..e4b699cdb1 100644 --- a/lib/python/qmk/constants.py +++ b/lib/python/qmk/constants.py @@ -17,6 +17,45 @@ CHIBIOS_PROCESSORS = 'cortex-m0', 'cortex-m0plus', 'cortex-m3', 'cortex-m4', 'MK LUFA_PROCESSORS = 'at90usb162', 'atmega16u2', 'atmega32u2', 'atmega16u4', 'atmega32u4', 'at90usb646', 'at90usb647', 'at90usb1286', 'at90usb1287', None VUSB_PROCESSORS = 'atmega32a', 'atmega328p', 'atmega328', 'attiny85' +# Bootloaders of the supported processors +MCU2BOOTLOADER = { + "MKL26Z64": "halfkay", + "MK20DX128": "halfkay", + "MK20DX256": "halfkay", + "MK66FX1M0": "halfkay", + "STM32F042": "stm32-dfu", + "STM32F072": "stm32-dfu", + "STM32F103": "stm32duino", + "STM32F303": "stm32-dfu", + "STM32F401": "stm32-dfu", + "STM32F405": "stm32-dfu", + "STM32F407": "stm32-dfu", + "STM32F411": "stm32-dfu", + "STM32F446": "stm32-dfu", + "STM32G431": "stm32-dfu", + "STM32G474": "stm32-dfu", + "STM32L412": "stm32-dfu", + "STM32L422": "stm32-dfu", + "STM32L432": "stm32-dfu", + "STM32L433": "stm32-dfu", + "STM32L442": "stm32-dfu", + "STM32L443": "stm32-dfu", + "GD32VF103": "gd32v-dfu", + "WB32F3G71": "wb32-dfu", + "atmega16u2": "atmel-dfu", + "atmega32u2": "atmel-dfu", + "atmega16u4": "atmel-dfu", + "atmega32u4": "atmel-dfu", + "at90usb162": "atmel-dfu", + "at90usb646": "atmel-dfu", + "at90usb647": "atmel-dfu", + "at90usb1286": "atmel-dfu", + "at90usb1287": "atmel-dfu", + "atmega32a": "bootloadhid", + "atmega328p": "usbasploader", + "atmega328": "usbasploader", +} + # Common format strings DATE_FORMAT = '%Y-%m-%d' DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S %Z' |