Brute force update CLI tools
This commit is contained in:
2
lib/python/qmk/cli/generate/__init__.py
Normal file
2
lib/python/qmk/cli/generate/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import api
|
||||
from . import docs
|
||||
58
lib/python/qmk/cli/generate/api.py
Executable file
58
lib/python/qmk/cli/generate/api.py
Executable file
@@ -0,0 +1,58 @@
|
||||
"""This script automates the generation of the QMK API data.
|
||||
"""
|
||||
from pathlib import Path
|
||||
from shutil import copyfile
|
||||
import json
|
||||
|
||||
from milc import cli
|
||||
|
||||
from qmk.datetime import current_datetime
|
||||
from qmk.info import info_json
|
||||
from qmk.keyboard import list_keyboards
|
||||
|
||||
|
||||
@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.
|
||||
"""
|
||||
api_data_dir = Path('api_data')
|
||||
v1_dir = api_data_dir / 'v1'
|
||||
keyboard_list = v1_dir / 'keyboard_list.json'
|
||||
keyboard_all = v1_dir / 'keyboards.json'
|
||||
usb_file = v1_dir / 'usb.json'
|
||||
|
||||
if not api_data_dir.exists():
|
||||
api_data_dir.mkdir()
|
||||
|
||||
kb_all = {'last_updated': current_datetime(), 'keyboards': {}}
|
||||
usb_list = {'last_updated': current_datetime(), 'devices': {}}
|
||||
|
||||
# Generate and write keyboard specific JSON files
|
||||
for keyboard_name in list_keyboards():
|
||||
kb_all['keyboards'][keyboard_name] = info_json(keyboard_name)
|
||||
keyboard_dir = v1_dir / 'keyboards' / keyboard_name
|
||||
keyboard_info = keyboard_dir / 'info.json'
|
||||
keyboard_readme = keyboard_dir / 'readme.md'
|
||||
keyboard_readme_src = Path('keyboards') / keyboard_name / 'readme.md'
|
||||
|
||||
keyboard_dir.mkdir(parents=True, exist_ok=True)
|
||||
keyboard_info.write_text(json.dumps(kb_all['keyboards'][keyboard_name]))
|
||||
|
||||
if keyboard_readme_src.exists():
|
||||
copyfile(keyboard_readme_src, keyboard_readme)
|
||||
|
||||
if 'usb' in kb_all['keyboards'][keyboard_name]:
|
||||
usb = kb_all['keyboards'][keyboard_name]['usb']
|
||||
|
||||
if usb['vid'] not in usb_list['devices']:
|
||||
usb_list['devices'][usb['vid']] = {}
|
||||
|
||||
if usb['pid'] not in usb_list['devices'][usb['vid']]:
|
||||
usb_list['devices'][usb['vid']][usb['pid']] = {}
|
||||
|
||||
usb_list['devices'][usb['vid']][usb['pid']][keyboard_name] = usb
|
||||
|
||||
# Write the global JSON files
|
||||
keyboard_list.write_text(json.dumps({'last_updated': current_datetime(), 'keyboards': sorted(kb_all['keyboards'])}))
|
||||
keyboard_all.write_text(json.dumps(kb_all))
|
||||
usb_file.write_text(json.dumps(usb_list))
|
||||
37
lib/python/qmk/cli/generate/docs.py
Normal file
37
lib/python/qmk/cli/generate/docs.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Build QMK documentation locally
|
||||
"""
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from milc import cli
|
||||
|
||||
DOCS_PATH = Path('docs/')
|
||||
BUILD_PATH = Path('.build/docs/')
|
||||
|
||||
|
||||
@cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True)
|
||||
def generate_docs(cli):
|
||||
"""Invoke the docs generation process
|
||||
|
||||
TODO(unclaimed):
|
||||
* [ ] Add a real build step... something static docs
|
||||
"""
|
||||
|
||||
if BUILD_PATH.exists():
|
||||
shutil.rmtree(BUILD_PATH)
|
||||
|
||||
shutil.copytree(DOCS_PATH, BUILD_PATH)
|
||||
|
||||
# When not verbose we want to hide all output
|
||||
args = {'check': True}
|
||||
if not cli.args.verbose:
|
||||
args.update({'stdout': subprocess.DEVNULL, 'stderr': subprocess.STDOUT})
|
||||
|
||||
cli.log.info('Generating internal docs...')
|
||||
|
||||
# Generate internal docs
|
||||
subprocess.run(['doxygen', 'Doxyfile'], **args)
|
||||
subprocess.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args)
|
||||
|
||||
cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH)
|
||||
Reference in New Issue
Block a user