summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/generate
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/generate')
-rwxr-xr-xlib/python/qmk/cli/generate/api.py35
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)