diff options
Diffstat (limited to 'lib/python/qmk/cli/generate/api.py')
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 50 |
1 files changed, 33 insertions, 17 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)) |