diff options
author | QMK Bot <hello@qmk.fm> | 2021-05-10 18:19:15 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2021-05-10 18:19:15 +0000 |
commit | 911b45ce3bcc2cf4c7e12ccf8df7da9621173e32 (patch) | |
tree | 1e01136ad436175dc74f9502e63dfeba21364380 /lib/python/qmk/cli/generate | |
parent | cfc6e4bfac6b677b2f1249552c9e95d063f9d459 (diff) | |
parent | a3e7f3e7c58ee98596ead5c213f3a9ed8340cd80 (diff) |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 70019428f0..8ab7522a76 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -13,6 +13,7 @@ from qmk.json_schema import json_load from qmk.keyboard import list_keyboards +@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") @cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) def generate_api(cli): """Generates the QMK API data. @@ -40,10 +41,14 @@ def generate_api(cli): 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[keyboard_name]}})) + keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) + if not cli.args.dry_run: + keyboard_info.write_text(keyboard_json) + cli.log.debug('Wrote file %s', keyboard_info) - if keyboard_readme_src.exists(): - copyfile(keyboard_readme_src, keyboard_readme) + if keyboard_readme_src.exists(): + copyfile(keyboard_readme_src, keyboard_readme) + cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) if 'usb' in kb_all[keyboard_name]: usb = kb_all[keyboard_name]['usb'] @@ -57,20 +62,26 @@ def generate_api(cli): if 'vid' in usb and 'pid' in usb: usb_list[usb['vid']][usb['pid']][keyboard_name] = usb - # Write the global JSON files - 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)) - + # Generate data for the global files 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)) + + # Write the global JSON files + keyboard_all_json = json.dumps({'last_updated': current_datetime(), 'keyboards': kb_all}, cls=InfoJSONEncoder) + usb_json = json.dumps({'last_updated': current_datetime(), 'usb': usb_list}, cls=InfoJSONEncoder) + keyboard_list_json = json.dumps({'last_updated': current_datetime(), 'keyboards': keyboard_list}, cls=InfoJSONEncoder) + keyboard_aliases_json = json.dumps({'last_updated': current_datetime(), 'keyboard_aliases': keyboard_aliases}, cls=InfoJSONEncoder) + keyboard_metadata_json = json.dumps(keyboard_metadata, cls=InfoJSONEncoder) + + if not cli.args.dry_run: + keyboard_all_file.write_text(keyboard_all_json) + usb_file.write_text(usb_json) + keyboard_list_file.write_text(keyboard_list_json) + keyboard_aliases_file.write_text(keyboard_aliases_json) + keyboard_metadata_file.write_text(keyboard_metadata_json) |