diff options
| author | Joel Challis <git@zvecr.com> | 2023-01-20 03:38:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-20 03:38:19 +0000 |
| commit | fe6502f12e12e1fe9691be4b2729cd7ac4c4aac6 (patch) | |
| tree | a5a38b4c7c8d35d9bc56a1b50f48da5e1be14b69 /lib/python/qmk/cli/generate/api.py | |
| parent | 27504d974d6ed6daeaf947d29e9f7ac4979b339e (diff) | |
Publish keymap.json to API (#19167)
Diffstat (limited to 'lib/python/qmk/cli/generate/api.py')
| -rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index d662e14e00..11d4616199 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py | |||
| @@ -43,7 +43,7 @@ def _resolve_keycode_specs(output_folder): | |||
| 43 | overall = load_spec(version) | 43 | overall = load_spec(version) |
| 44 | 44 | ||
| 45 | output_file = output_folder / f'constants/keycodes_{version}.json' | 45 | output_file = output_folder / f'constants/keycodes_{version}.json' |
| 46 | output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8') | 46 | output_file.write_text(json.dumps(overall), encoding='utf-8') |
| 47 | 47 | ||
| 48 | for lang in list_languages(): | 48 | for lang in list_languages(): |
| 49 | for version in list_versions(lang): | 49 | for version in list_versions(lang): |
| @@ -64,7 +64,7 @@ def _filtered_copy(src, dst): | |||
| 64 | data = json_load(src) | 64 | data = json_load(src) |
| 65 | 65 | ||
| 66 | dst = dst.with_suffix('.json') | 66 | dst = dst.with_suffix('.json') |
| 67 | dst.write_text(json.dumps(data, indent=4), encoding='utf-8') | 67 | dst.write_text(json.dumps(data), encoding='utf-8') |
| 68 | return dst | 68 | return dst |
| 69 | 69 | ||
| 70 | return shutil.copy2(src, dst) | 70 | return shutil.copy2(src, dst) |
| @@ -111,29 +111,44 @@ def generate_api(cli): | |||
| 111 | 111 | ||
| 112 | # Generate and write keyboard specific JSON files | 112 | # Generate and write keyboard specific JSON files |
| 113 | for keyboard_name in keyboard_list: | 113 | for keyboard_name in keyboard_list: |
| 114 | kb_all[keyboard_name] = info_json(keyboard_name) | 114 | kb_json = info_json(keyboard_name) |
| 115 | 115 | kb_all[keyboard_name] = kb_json | |
| 116 | # Populate the list of JSON keymaps | ||
| 117 | for keymap in list_keymaps(keyboard_name, c=False, fullpath=True): | ||
| 118 | kb_all[keyboard_name]['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} | ||
| 119 | 116 | ||
| 120 | keyboard_dir = v1_dir / 'keyboards' / keyboard_name | 117 | keyboard_dir = v1_dir / 'keyboards' / keyboard_name |
| 121 | keyboard_info = keyboard_dir / 'info.json' | 118 | keyboard_info = keyboard_dir / 'info.json' |
| 122 | keyboard_readme = keyboard_dir / 'readme.md' | 119 | keyboard_readme = keyboard_dir / 'readme.md' |
| 123 | keyboard_readme_src = find_readme(keyboard_name) | 120 | keyboard_readme_src = find_readme(keyboard_name) |
| 124 | 121 | ||
| 122 | # Populate the list of JSON keymaps | ||
| 123 | for keymap in list_keymaps(keyboard_name, c=False, fullpath=True): | ||
| 124 | kb_json['keymaps'][keymap.name] = { | ||
| 125 | # TODO: deprecate 'url' as consumer needs to know its potentially hjson | ||
| 126 | 'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json', | ||
| 127 | |||
| 128 | # Instead consumer should grab from API and not repo directly | ||
| 129 | 'path': (keymap / 'keymap.json').as_posix(), | ||
| 130 | } | ||
| 131 | |||
| 125 | keyboard_dir.mkdir(parents=True, exist_ok=True) | 132 | keyboard_dir.mkdir(parents=True, exist_ok=True) |
| 126 | keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) | 133 | keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}) |
| 127 | if not cli.args.dry_run: | 134 | if not cli.args.dry_run: |
| 128 | keyboard_info.write_text(keyboard_json) | 135 | keyboard_info.write_text(keyboard_json, encoding='utf-8') |
| 129 | cli.log.debug('Wrote file %s', keyboard_info) | 136 | cli.log.debug('Wrote file %s', keyboard_info) |
| 130 | 137 | ||
| 131 | if keyboard_readme_src: | 138 | if keyboard_readme_src: |
| 132 | shutil.copyfile(keyboard_readme_src, keyboard_readme) | 139 | shutil.copyfile(keyboard_readme_src, keyboard_readme) |
| 133 | cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) | 140 | cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) |
| 134 | 141 | ||
| 135 | if 'usb' in kb_all[keyboard_name]: | 142 | # resolve keymaps as json |
| 136 | usb = kb_all[keyboard_name]['usb'] | 143 | for keymap in kb_json['keymaps']: |
| 144 | keymap_hjson = kb_json['keymaps'][keymap]['path'] | ||
| 145 | keymap_json = v1_dir / keymap_hjson | ||
| 146 | keymap_json.parent.mkdir(parents=True, exist_ok=True) | ||
| 147 | keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson))), encoding='utf-8') | ||
| 148 | cli.log.debug('Wrote keymap %s', keymap_json) | ||
| 149 | |||
| 150 | if 'usb' in kb_json: | ||
| 151 | usb = kb_json['usb'] | ||
| 137 | 152 | ||
| 138 | if 'vid' in usb and usb['vid'] not in usb_list: | 153 | if 'vid' in usb and usb['vid'] not in usb_list: |
| 139 | usb_list[usb['vid']] = {} | 154 | usb_list[usb['vid']] = {} |
| @@ -166,9 +181,9 @@ def generate_api(cli): | |||
| 166 | constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) | 181 | constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) |
| 167 | 182 | ||
| 168 | if not cli.args.dry_run: | 183 | if not cli.args.dry_run: |
| 169 | keyboard_all_file.write_text(keyboard_all_json) | 184 | keyboard_all_file.write_text(keyboard_all_json, encoding='utf-8') |
| 170 | usb_file.write_text(usb_json) | 185 | usb_file.write_text(usb_json, encoding='utf-8') |
| 171 | keyboard_list_file.write_text(keyboard_list_json) | 186 | keyboard_list_file.write_text(keyboard_list_json, encoding='utf-8') |
| 172 | keyboard_aliases_file.write_text(keyboard_aliases_json) | 187 | keyboard_aliases_file.write_text(keyboard_aliases_json, encoding='utf-8') |
| 173 | keyboard_metadata_file.write_text(keyboard_metadata_json) | 188 | keyboard_metadata_file.write_text(keyboard_metadata_json, encoding='utf-8') |
| 174 | constants_metadata_file.write_text(constants_metadata_json) | 189 | constants_metadata_file.write_text(constants_metadata_json, encoding='utf-8') |
