mirror of
				https://github.com/mfulz/qmk_firmware.git
				synced 2025-10-31 05:12:33 +01:00 
			
		
		
		
	Publish keymap.json to API (#19167)
This commit is contained in:
		
							parent
							
								
									27504d974d
								
							
						
					
					
						commit
						fe6502f12e
					
				| @ -43,7 +43,7 @@ def _resolve_keycode_specs(output_folder): | |||||||
|         overall = load_spec(version) |         overall = load_spec(version) | ||||||
| 
 | 
 | ||||||
|         output_file = output_folder / f'constants/keycodes_{version}.json' |         output_file = output_folder / f'constants/keycodes_{version}.json' | ||||||
|         output_file.write_text(json.dumps(overall, indent=4), encoding='utf-8') |         output_file.write_text(json.dumps(overall), encoding='utf-8') | ||||||
| 
 | 
 | ||||||
|     for lang in list_languages(): |     for lang in list_languages(): | ||||||
|         for version in list_versions(lang): |         for version in list_versions(lang): | ||||||
| @ -64,7 +64,7 @@ def _filtered_copy(src, dst): | |||||||
|         data = json_load(src) |         data = json_load(src) | ||||||
| 
 | 
 | ||||||
|         dst = dst.with_suffix('.json') |         dst = dst.with_suffix('.json') | ||||||
|         dst.write_text(json.dumps(data, indent=4), encoding='utf-8') |         dst.write_text(json.dumps(data), encoding='utf-8') | ||||||
|         return dst |         return dst | ||||||
| 
 | 
 | ||||||
|     return shutil.copy2(src, dst) |     return shutil.copy2(src, dst) | ||||||
| @ -111,29 +111,44 @@ def generate_api(cli): | |||||||
| 
 | 
 | ||||||
|     # Generate and write keyboard specific JSON files |     # Generate and write keyboard specific JSON files | ||||||
|     for keyboard_name in keyboard_list: |     for keyboard_name in keyboard_list: | ||||||
|         kb_all[keyboard_name] = info_json(keyboard_name) |         kb_json = info_json(keyboard_name) | ||||||
| 
 |         kb_all[keyboard_name] = kb_json | ||||||
|         # Populate the list of JSON keymaps |  | ||||||
|         for keymap in list_keymaps(keyboard_name, c=False, fullpath=True): |  | ||||||
|             kb_all[keyboard_name]['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'} |  | ||||||
| 
 | 
 | ||||||
|         keyboard_dir = v1_dir / 'keyboards' / keyboard_name |         keyboard_dir = v1_dir / 'keyboards' / keyboard_name | ||||||
|         keyboard_info = keyboard_dir / 'info.json' |         keyboard_info = keyboard_dir / 'info.json' | ||||||
|         keyboard_readme = keyboard_dir / 'readme.md' |         keyboard_readme = keyboard_dir / 'readme.md' | ||||||
|         keyboard_readme_src = find_readme(keyboard_name) |         keyboard_readme_src = find_readme(keyboard_name) | ||||||
| 
 | 
 | ||||||
|  |         # Populate the list of JSON keymaps | ||||||
|  |         for keymap in list_keymaps(keyboard_name, c=False, fullpath=True): | ||||||
|  |             kb_json['keymaps'][keymap.name] = { | ||||||
|  |                 # TODO: deprecate 'url' as consumer needs to know its potentially hjson | ||||||
|  |                 'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json', | ||||||
|  | 
 | ||||||
|  |                 # Instead consumer should grab from API and not repo directly | ||||||
|  |                 'path': (keymap / 'keymap.json').as_posix(), | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|         keyboard_dir.mkdir(parents=True, exist_ok=True) |         keyboard_dir.mkdir(parents=True, exist_ok=True) | ||||||
|         keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) |         keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_json}}) | ||||||
|         if not cli.args.dry_run: |         if not cli.args.dry_run: | ||||||
|             keyboard_info.write_text(keyboard_json) |             keyboard_info.write_text(keyboard_json, encoding='utf-8') | ||||||
|             cli.log.debug('Wrote file %s', keyboard_info) |             cli.log.debug('Wrote file %s', keyboard_info) | ||||||
| 
 | 
 | ||||||
|             if keyboard_readme_src: |             if keyboard_readme_src: | ||||||
|                 shutil.copyfile(keyboard_readme_src, keyboard_readme) |                 shutil.copyfile(keyboard_readme_src, keyboard_readme) | ||||||
|                 cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) |                 cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) | ||||||
| 
 | 
 | ||||||
|         if 'usb' in kb_all[keyboard_name]: |             # resolve keymaps as json | ||||||
|             usb = kb_all[keyboard_name]['usb'] |             for keymap in kb_json['keymaps']: | ||||||
|  |                 keymap_hjson = kb_json['keymaps'][keymap]['path'] | ||||||
|  |                 keymap_json = v1_dir / keymap_hjson | ||||||
|  |                 keymap_json.parent.mkdir(parents=True, exist_ok=True) | ||||||
|  |                 keymap_json.write_text(json.dumps(json_load(Path(keymap_hjson))), encoding='utf-8') | ||||||
|  |                 cli.log.debug('Wrote keymap %s', keymap_json) | ||||||
|  | 
 | ||||||
|  |         if 'usb' in kb_json: | ||||||
|  |             usb = kb_json['usb'] | ||||||
| 
 | 
 | ||||||
|             if 'vid' in usb and usb['vid'] not in usb_list: |             if 'vid' in usb and usb['vid'] not in usb_list: | ||||||
|                 usb_list[usb['vid']] = {} |                 usb_list[usb['vid']] = {} | ||||||
| @ -166,9 +181,9 @@ def generate_api(cli): | |||||||
|     constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) |     constants_metadata_json = json.dumps({'last_updated': current_datetime(), 'constants': _list_constants(v1_dir)}) | ||||||
| 
 | 
 | ||||||
|     if not cli.args.dry_run: |     if not cli.args.dry_run: | ||||||
|         keyboard_all_file.write_text(keyboard_all_json) |         keyboard_all_file.write_text(keyboard_all_json, encoding='utf-8') | ||||||
|         usb_file.write_text(usb_json) |         usb_file.write_text(usb_json, encoding='utf-8') | ||||||
|         keyboard_list_file.write_text(keyboard_list_json) |         keyboard_list_file.write_text(keyboard_list_json, encoding='utf-8') | ||||||
|         keyboard_aliases_file.write_text(keyboard_aliases_json) |         keyboard_aliases_file.write_text(keyboard_aliases_json, encoding='utf-8') | ||||||
|         keyboard_metadata_file.write_text(keyboard_metadata_json) |         keyboard_metadata_file.write_text(keyboard_metadata_json, encoding='utf-8') | ||||||
|         constants_metadata_file.write_text(constants_metadata_json) |         constants_metadata_file.write_text(constants_metadata_json, encoding='utf-8') | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Joel Challis
						Joel Challis