diff options
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r-- | lib/python/qmk/cli/c2json.py | 3 | ||||
-rwxr-xr-x | lib/python/qmk/cli/compile.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/cli/flash.py | 3 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 50 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/config_h.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/info_json.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/layouts.py | 3 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/info.py | 4 | ||||
-rw-r--r-- | lib/python/qmk/cli/list/keymaps.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/new/keymap.py | 3 |
11 files changed, 62 insertions, 39 deletions
diff --git a/lib/python/qmk/cli/c2json.py b/lib/python/qmk/cli/c2json.py index b9d55ebdbc..a97e212223 100644 --- a/lib/python/qmk/cli/c2json.py +++ b/lib/python/qmk/cli/c2json.py @@ -7,12 +7,13 @@ from milc import cli import qmk.keymap import qmk.path from qmk.info_json_encoder import InfoJSONEncoder +from qmk.keyboard import keyboard_folder @cli.argument('--no-cpp', arg_only=True, action='store_false', help='Do not use \'cpp\' on keymap.c') @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") -@cli.argument('-kb', '--keyboard', arg_only=True, required=True, help='The keyboard\'s name') +@cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, required=True, help='The keyboard\'s name') @cli.argument('-km', '--keymap', arg_only=True, required=True, help='The keymap\'s name') @cli.argument('filename', arg_only=True, help='keymap.c file') @cli.subcommand('Creates a keymap.json from a keymap.c file.') diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index db195f78a5..5793e98928 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py @@ -7,10 +7,11 @@ from milc import cli import qmk.path from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json +from qmk.keyboard import keyboard_folder @cli.argument('filename', nargs='?', arg_only=True, type=qmk.path.FileType('r'), help='The configurator export to compile') -@cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py index 173dee3df5..c9273c3f98 100644 --- a/lib/python/qmk/cli/flash.py +++ b/lib/python/qmk/cli/flash.py @@ -9,6 +9,7 @@ from milc import cli import qmk.path from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json +from qmk.keyboard import keyboard_folder def print_bootloader_help(): @@ -33,7 +34,7 @@ def print_bootloader_help(): @cli.argument('-b', '--bootloaders', action='store_true', help='List the available bootloaders.') @cli.argument('-bl', '--bootloader', default='flash', help='The flash command, corresponding to qmk\'s make options of bootloaders.') @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.') -@cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='The keyboard to build a firmware for. Use this if you dont have a configurator file. Ignored when a configurator file is supplied.') @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") @cli.argument('-j', '--parallel', type=int, default=1, help="Set the number of parallel make jobs to run.") @cli.argument('-e', '--env', arg_only=True, action='append', default=[], help="Set a variable to be passed to make. May be passed multiple times.") diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 6d111f244c..9870f7201d 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -9,6 +9,7 @@ from milc import cli from qmk.datetime import current_datetime from qmk.info import info_json from qmk.info_json_encoder import InfoJSONEncoder +from qmk.json_schema import json_load from qmk.keyboard import list_keyboards @@ -18,43 +19,58 @@ def generate_api(cli): """ api_data_dir = Path('api_data') v1_dir = api_data_dir / 'v1' - keyboard_list = v1_dir / 'keyboard_list.json' - keyboard_all = v1_dir / 'keyboards.json' - usb_file = v1_dir / 'usb.json' + keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything + keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets + keyboard_aliases_file = v1_dir / 'keyboard_aliases.json' # A list of historical keyboard names and their new name + keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization + usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target if not api_data_dir.exists(): api_data_dir.mkdir() - kb_all = {'last_updated': current_datetime(), 'keyboards': {}} - usb_list = {'last_updated': current_datetime(), 'devices': {}} + kb_all = {} + usb_list = {} # Generate and write keyboard specific JSON files for keyboard_name in list_keyboards(): - kb_all['keyboards'][keyboard_name] = info_json(keyboard_name) + kb_all[keyboard_name] = info_json(keyboard_name) keyboard_dir = v1_dir / 'keyboards' / keyboard_name keyboard_info = keyboard_dir / 'info.json' keyboard_readme = keyboard_dir / 'readme.md' keyboard_readme_src = Path('keyboards') / keyboard_name / 'readme.md' keyboard_dir.mkdir(parents=True, exist_ok=True) - keyboard_info.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all['keyboards'][keyboard_name]}})) + keyboard_info.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}})) if keyboard_readme_src.exists(): copyfile(keyboard_readme_src, keyboard_readme) - if 'usb' in kb_all['keyboards'][keyboard_name]: - usb = kb_all['keyboards'][keyboard_name]['usb'] + if 'usb' in kb_all[keyboard_name]: + usb = kb_all[keyboard_name]['usb'] - if 'vid' in usb and usb['vid'] not in usb_list['devices']: - usb_list['devices'][usb['vid']] = {} + if 'vid' in usb and usb['vid'] not in usb_list: + usb_list[usb['vid']] = {} - if 'pid' in usb and usb['pid'] not in usb_list['devices'][usb['vid']]: - usb_list['devices'][usb['vid']][usb['pid']] = {} + if 'pid' in usb and usb['pid'] not in usb_list[usb['vid']]: + usb_list[usb['vid']][usb['pid']] = {} if 'vid' in usb and 'pid' in usb: - usb_list['devices'][usb['vid']][usb['pid']][keyboard_name] = usb + usb_list[usb['vid']][usb['pid']][keyboard_name] = usb # Write the global JSON files - keyboard_list.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': sorted(kb_all['keyboards'])}, cls=InfoJSONEncoder)) - keyboard_all.write_text(json.dumps(kb_all, cls=InfoJSONEncoder)) - usb_file.write_text(json.dumps(usb_list, cls=InfoJSONEncoder)) + keyboard_all_file.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, cls=InfoJSONEncoder)) + usb_file.write_text(json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, cls=InfoJSONEncoder)) + + keyboard_list = sorted(kb_all) + keyboard_list_file.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder)) + + keyboard_aliases = json_load(Path('data/mappings/keyboard_aliases.json')) + keyboard_aliases_file.write_text(json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder)) + + keyboard_metadata = { + 'last_updated': current_datetime(), + 'keyboards': keyboard_list, + 'keyboard_aliases': keyboard_aliases, + 'usb': usb_list + } + keyboard_metadata_file.write_text(json.dumps(keyboard_metadata, cls=InfoJSONEncoder)) diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index e6d49ea4d5..ccea6d7a05 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -6,7 +6,9 @@ from dotty_dict import dotty from milc import cli from qmk.decorators import automagic_keyboard, automagic_keymap -from qmk.info import _json_load, info_json +from qmk.info import info_json +from qmk.json_schema import json_load +from qmk.keyboard import keyboard_folder from qmk.path import is_keyboard, normpath @@ -73,7 +75,7 @@ def matrix_pins(matrix_pins): @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") -@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='Keyboard to generate config.h for.') @cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) @automagic_keyboard @automagic_keymap @@ -92,7 +94,7 @@ def generate_config_h(cli): # Build the info_config.h file. kb_info_json = dotty(info_json(cli.config.generate_config_h.keyboard)) - info_config_map = _json_load(Path('data/mappings/info_config.json')) + info_config_map = json_load(Path('data/mappings/info_config.json')) config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once'] diff --git a/lib/python/qmk/cli/generate/info_json.py b/lib/python/qmk/cli/generate/info_json.py index f3fc54ddcf..6c00ba7d8a 100755 --- a/lib/python/qmk/cli/generate/info_json.py +++ b/lib/python/qmk/cli/generate/info_json.py @@ -8,8 +8,10 @@ from jsonschema import Draft7Validator, validators from milc import cli from qmk.decorators import automagic_keyboard, automagic_keymap -from qmk.info import info_json, _jsonschema +from qmk.info import info_json from qmk.info_json_encoder import InfoJSONEncoder +from qmk.json_schema import load_jsonschema +from qmk.keyboard import keyboard_folder from qmk.path import is_keyboard @@ -33,13 +35,13 @@ def strip_info_json(kb_info_json): """Remove the API-only properties from the info.json. """ pruning_draft_7_validator = pruning_validator(Draft7Validator) - schema = _jsonschema('keyboard') + schema = load_jsonschema('keyboard') validator = pruning_draft_7_validator(schema).validate return validator(kb_info_json) -@cli.argument('-kb', '--keyboard', help='Keyboard to show info for.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='Keyboard to show info for.') @cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') @cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True) @automagic_keyboard diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py index a738edfe64..7b4394291f 100755 --- a/lib/python/qmk/cli/generate/layouts.py +++ b/lib/python/qmk/cli/generate/layouts.py @@ -5,6 +5,7 @@ from milc import cli from qmk.constants import COL_LETTERS, ROW_LETTERS from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.info import info_json +from qmk.keyboard import keyboard_folder from qmk.path import is_keyboard, normpath usb_properties = { @@ -16,7 +17,7 @@ usb_properties = { @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") -@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='Keyboard to generate config.h for.') @cli.subcommand('Used by the make system to generate layouts.h from info.json', hidden=True) @automagic_keyboard @automagic_keymap diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 15917987b9..91759d26c6 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -6,7 +6,9 @@ from dotty_dict import dotty from milc import cli from qmk.decorators import automagic_keyboard, automagic_keymap -from qmk.info import _json_load, info_json +from qmk.info import info_json +from qmk.json_schema import json_load +from qmk.keyboard import keyboard_folder from qmk.path import is_keyboard, normpath @@ -37,7 +39,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") @cli.argument('-e', '--escape', arg_only=True, action='store_true', help="Escape spaces in quiet mode") -@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='Keyboard to generate config.h for.') @cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) @automagic_keyboard @automagic_keymap @@ -54,7 +56,7 @@ def generate_rules_mk(cli): return False kb_info_json = dotty(info_json(cli.config.generate_rules_mk.keyboard)) - info_rules_map = _json_load(Path('data/mappings/info_rules.json')) + info_rules_map = json_load(Path('data/mappings/info_rules.json')) rules_mk_lines = ['# This file was generated by `qmk generate-rules-mk`. Do not edit or copy.', ''] # Iterate through the info_rules map to generate basic rules diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index a7ce8abf03..88b65686f5 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py @@ -10,7 +10,7 @@ from milc import cli from qmk.info_json_encoder import InfoJSONEncoder from qmk.constants import COL_LETTERS, ROW_LETTERS from qmk.decorators import automagic_keyboard, automagic_keymap -from qmk.keyboard import render_layouts, render_layout +from qmk.keyboard import keyboard_folder, render_layouts, render_layout from qmk.keymap import locate_keymap from qmk.info import info_json from qmk.path import is_keyboard @@ -124,7 +124,7 @@ def print_text_output(kb_info_json): show_keymap(kb_info_json, False) -@cli.argument('-kb', '--keyboard', help='Keyboard to show info for.') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, help='Keyboard to show info for.') @cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') @cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.') @cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.') diff --git a/lib/python/qmk/cli/list/keymaps.py b/lib/python/qmk/cli/list/keymaps.py index 49bc84b2ce..7c0ad43997 100644 --- a/lib/python/qmk/cli/list/keymaps.py +++ b/lib/python/qmk/cli/list/keymaps.py @@ -4,18 +4,14 @@ from milc import cli import qmk.keymap from qmk.decorators import automagic_keyboard -from qmk.path import is_keyboard +from qmk.keyboard import keyboard_folder -@cli.argument("-kb", "--keyboard", help="Specify keyboard name. Example: 1upkeyboards/1up60hse") +@cli.argument("-kb", "--keyboard", type=keyboard_folder, help="Specify keyboard name. Example: 1upkeyboards/1up60hse") @cli.subcommand("List the keymaps for a specific keyboard") @automagic_keyboard def list_keymaps(cli): """List the keymaps for a specific keyboard """ - if not is_keyboard(cli.config.list_keymaps.keyboard): - cli.log.error('Keyboard %s does not exist!', cli.config.list_keymaps.keyboard) - return False - for name in qmk.keymap.list_keymaps(cli.config.list_keymaps.keyboard): print(name) diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py index 52c564997b..ea98a287c1 100755 --- a/lib/python/qmk/cli/new/keymap.py +++ b/lib/python/qmk/cli/new/keymap.py @@ -5,10 +5,11 @@ from pathlib import Path import qmk.path from qmk.decorators import automagic_keyboard, automagic_keymap +from qmk.keyboard import keyboard_folder from milc import cli -@cli.argument('-kb', '--keyboard', help='Specify keyboard name. Example: 1upkeyboards/1up60hse') +@cli.argument('-kb', '--keyboard', type=keyboard_folder, 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') @automagic_keyboard |