summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-03-24 09:26:38 -0700
committerGitHub <noreply@github.com>2021-03-24 09:26:38 -0700
commit299008be36076343edadb7a36bf2fff820425ad1 (patch)
treed47d2fddc54b329b4ddb3128ef070b4cdba776a4 /lib/python/qmk/cli/generate
parent723d9af04d610c4a2fcb8fcf39e8420c71ed4df0 (diff)
Add support for qmk_configurator style aliases (#11954)
* Add support for qmk_configurator style aliases * add the keyboard aliases to the api data * add support for a keyboard metadata file * make flake8 happy
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-xlib/python/qmk/cli/generate/api.py50
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py8
-rwxr-xr-xlib/python/qmk/cli/generate/info_json.py8
-rwxr-xr-xlib/python/qmk/cli/generate/layouts.py3
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py8
5 files changed, 50 insertions, 27 deletions
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