diff options
| author | Joel Challis <git@zvecr.com> | 2022-08-06 07:14:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-06 16:14:29 +1000 |
| commit | 897403c4a71080469b8c11fc87e0e145ffe3837a (patch) | |
| tree | edaf919a687f0f908b534b5a5d74e3a0432741c7 /lib/python/qmk/cli/generate/api.py | |
| parent | ec5186f0f9e2d1910331785f1410be5892058ee4 (diff) | |
Publish data as part of API generation (#17020)
Diffstat (limited to 'lib/python/qmk/cli/generate/api.py')
| -rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 0596b3f22b..8d8ca3cd41 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py | |||
| @@ -12,21 +12,30 @@ from qmk.json_encoders import InfoJSONEncoder | |||
| 12 | from qmk.json_schema import json_load | 12 | from qmk.json_schema import json_load |
| 13 | from qmk.keyboard import find_readme, list_keyboards | 13 | from qmk.keyboard import find_readme, list_keyboards |
| 14 | 14 | ||
| 15 | TEMPLATE_PATH = Path('data/templates/api/') | 15 | DATA_PATH = Path('data') |
| 16 | TEMPLATE_PATH = DATA_PATH / 'templates/api/' | ||
| 16 | BUILD_API_PATH = Path('.build/api_data/') | 17 | BUILD_API_PATH = Path('.build/api_data/') |
| 17 | 18 | ||
| 18 | 19 | ||
| 20 | def _filtered_keyboard_list(): | ||
| 21 | """Perform basic filtering of list_keyboards | ||
| 22 | """ | ||
| 23 | keyboard_list = list_keyboards() | ||
| 24 | if cli.args.filter: | ||
| 25 | kb_list = [] | ||
| 26 | for keyboard_name in keyboard_list: | ||
| 27 | if any(i in keyboard_name for i in cli.args.filter): | ||
| 28 | kb_list.append(keyboard_name) | ||
| 29 | keyboard_list = kb_list | ||
| 30 | return keyboard_list | ||
| 31 | |||
| 32 | |||
| 19 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") | 33 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") |
| 20 | @cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on partial name matches the supplied value. May be passed multiple times.") | 34 | @cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on partial name matches the supplied value. May be passed multiple times.") |
| 21 | @cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True) | 35 | @cli.subcommand('Generate QMK API data', hidden=False if cli.config.user.developer else True) |
| 22 | def generate_api(cli): | 36 | def generate_api(cli): |
| 23 | """Generates the QMK API data. | 37 | """Generates the QMK API data. |
| 24 | """ | 38 | """ |
| 25 | if BUILD_API_PATH.exists(): | ||
| 26 | shutil.rmtree(BUILD_API_PATH) | ||
| 27 | |||
| 28 | shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH) | ||
| 29 | |||
| 30 | v1_dir = BUILD_API_PATH / 'v1' | 39 | v1_dir = BUILD_API_PATH / 'v1' |
| 31 | keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything | 40 | keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything |
| 32 | keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets | 41 | keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets |
| @@ -34,14 +43,14 @@ def generate_api(cli): | |||
| 34 | keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization | 43 | keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization |
| 35 | usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target | 44 | usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target |
| 36 | 45 | ||
| 46 | if BUILD_API_PATH.exists(): | ||
| 47 | shutil.rmtree(BUILD_API_PATH) | ||
| 48 | |||
| 49 | shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH) | ||
| 50 | shutil.copytree(DATA_PATH, v1_dir) | ||
| 51 | |||
| 37 | # Filter down when required | 52 | # Filter down when required |
| 38 | keyboard_list = list_keyboards() | 53 | keyboard_list = _filtered_keyboard_list() |
| 39 | if cli.args.filter: | ||
| 40 | kb_list = [] | ||
| 41 | for keyboard_name in keyboard_list: | ||
| 42 | if any(i in keyboard_name for i in cli.args.filter): | ||
| 43 | kb_list.append(keyboard_name) | ||
| 44 | keyboard_list = kb_list | ||
| 45 | 54 | ||
| 46 | kb_all = {} | 55 | kb_all = {} |
| 47 | usb_list = {} | 56 | usb_list = {} |
