Decouple lighting_map from XAP

This commit is contained in:
zvecr
2023-03-21 15:05:40 +00:00
parent 5eed80c66b
commit 42895141de
13 changed files with 1206 additions and 1178 deletions
+2 -36
View File
@@ -1,7 +1,5 @@
"""This script handles the XAP protocol data files.
"""
import re
import os
import hjson
import jsonschema
from pathlib import Path
@@ -10,6 +8,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
import qmk.constants
from qmk.git import git_get_version
from qmk.lighting import load_lighting_spec
from qmk.json_schema import json_load, validate, merge_ordered_dicts
from qmk.makefile import parse_rules_mk_file
from qmk.decorators import lru_cache
@@ -21,41 +20,8 @@ USERSPACE_DIR = Path('users')
XAP_SPEC = 'xap.hjson'
def list_lighting_versions(feature):
"""Return available versions - sorted newest first
"""
ret = []
for file in Path('data/constants/').glob(f'{feature}_[0-9].[0-9].[0-9].json'):
ret.append(file.stem.split('_')[-1])
ret.sort(reverse=True)
return ret
def load_lighting_spec(feature, version='latest'):
"""Build lighting data from the requested spec file
"""
if version == 'latest':
version = list_lighting_versions(feature)[0]
spec = json_load(Path(f'data/constants/{feature}_{version}.json'))
# preprocess for gross rgblight "mode + n"
for obj in spec.get('effects', {}).values():
define = obj['key']
offset = 0
found = re.match('(.*)_(\\d+)$', define)
if found:
define = found.group(1)
offset = int(found.group(2)) - 1
obj['define'] = define
obj['offset'] = offset
return spec
def _get_jinja2_env(data_templates_xap_subdir: str):
templates_dir = os.path.join(qmk.constants.QMK_FIRMWARE, 'data', 'templates', 'xap', data_templates_xap_subdir)
templates_dir = qmk.constants.QMK_FIRMWARE / 'data/templates/xap' / data_templates_xap_subdir
j2 = Environment(loader=FileSystemLoader(templates_dir), autoescape=select_autoescape(), lstrip_blocks=True, trim_blocks=True)
return j2