Files
mainline-status/regen.py
Dmitry Baryshkov a32d02c1ea soc: add product names
Add marketing (product) names for SoCs.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
2025-12-21 05:09:31 +02:00

155 lines
5.1 KiB
Python
Executable File

#!/usr/bin/python3
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
def write_autogenerated(out):
out.write('{%comment%}\nAUTOGENERATED FILE, please run ./regen.py to regenerate it\n{%endcomment%}\n\n')
def write_status_tag(out, name):
out.write('{%% include_cached status.liquid status=%s comment=%s-comment %%}' % (name, name))
def is_intop(v):
return 'intop' in v and v['intop']
def filter_intop(data):
return {k: v for k, v in data.items() if is_intop(v)}.items()
def filter_nop(data):
return data.items()
def filter_dict(data, filter_fn):
return {k: v for k, v in data.items() if filter_fn(v)}.items()
def write_header_int(out, data, filter_fn):
for (k, v) in filter_fn(data):
out.write('<th>%s</th>\n' % (v['name']))
def write_header(out, data, filter_fn):
out.write('<th>Platform</th>\n')
write_header_int(out, data, filter_fn)
out.write('<th>Platform</th>\n')
def write_header_nested(out, data, filter_fn):
out.write('<th rowspan="2">Platform</th>\n')
for (k, v) in filter_fn(data):
if 'items' in v and (intops := len(filter_fn(v['items']))):
out.write('<th colspan="%d">%s</th>\n' % (intops,v['name']))
else:
out.write('<th rowspan="2">%s</th>\n' % (v['name']))
out.write('<th rowspan="2">Platform</th>\n')
out.write('</tr>\n')
out.write('<tr>\n')
for (k, v) in data.items():
if not 'items' in v:
continue
if 'items' in v:
write_header_int(out, v['items'], filter_fn)
def write_layout(out, data, prefix, wrap=True):
for (k, v) in data.items():
if not wrap:
wrap = True
out.write(' ')
else:
out.write('<tr>')
out.write('<th>%s</th>' % v['name'])
write_status_tag(out, '%s-%s' % (prefix, k))
out.write('<td>{{ %s-%s-comment }}</td>\n' % (prefix, k))
out.write('</tr>\n')
def write_layout_nested(out, data, prefix):
for (k, v) in data.items():
if 'items' in v:
out.write('<th rowspan="%d">%s</th>\n' % (len(v['items']), v['name']))
write_layout(out, v['items'], prefix + '-' + k, wrap = False)
else:
out.write('<tr><th colspan="2">%s</th>' % (v['name']))
write_status_tag(out, '%s-%s' % (prefix, k))
out.write('<td>{{ %s-%s-comment }}</td>\n' % (prefix, k))
out.write('</tr>\n')
def write_status(out, data, prefix, filter_fn):
for (k, v) in filter_fn(data):
if 'items' in v and len(filter_fn(v['items'])):
write_status(out, v['items'], prefix + '-' + k, filter_fn)
else:
write_status_tag(out, '%s-%s' % (prefix, k))
out.write('\n')
def generate_template(data, prefix, check_fn):
for (k, v) in data.items():
if 'items' not in v:
yield '%s-%s' % (prefix, k)
if 'items' in v and len(filter_dict(v['items'], check_fn)) == 0 and check_fn(v):
yield '%s-%s' % (prefix, k)
if 'items' in v:
yield from generate_template(v['items'], prefix + '-' + k, check_fn)
def handle_soc_pmic(data, kind, prefix, is_soc):
has_nested = False
for (k, v) in data.items():
if 'items' in v:
has_nested = True
break
with open('_includes/index_%s_header.liquid' % kind, 'w') as out:
write_autogenerated(out)
out.write('<tr>\n')
if has_nested:
write_header_nested(out, data, filter_intop)
else:
write_header(out, data, filter_intop)
out.write('</tr>\n')
with open('_includes/index_%s_status.liquid' % kind, 'w') as out:
write_autogenerated(out)
write_status(out, data, 'd.' + prefix, filter_intop)
with open('_includes/full_%s_header.liquid' % kind, 'w') as out:
write_autogenerated(out)
out.write('<tr>\n')
if has_nested:
write_header_nested(out, data, filter_nop)
else:
write_header(out, data, filter_nop)
out.write('</tr>\n')
with open('_includes/full_%s_status.liquid' % kind, 'w') as out:
write_autogenerated(out)
write_status(out, data, 'd.' + prefix, filter_nop)
with open('_includes/layout_%s.liquid' % kind, 'w') as out:
write_autogenerated(out)
if has_nested:
write_layout_nested(out, data, 'page.' + prefix)
else:
write_layout(out, data, 'page.' + prefix)
with open('_%s.template' % kind, 'w') as out:
out.write('---\n')
out.write('name: ???\n')
if is_soc:
out.write('skus: [??, ??]\n')
out.write('fullname: ??\n')
out.write('layout: %s\n' % kind)
out.write(': N/A\n'.join(sorted(generate_template(data, prefix, is_intop))))
out.write(': N/A\n')
out.write('---\n')
with open('soc.yaml', "r") as file:
data = load(file, Loader=Loader)
handle_soc_pmic(data, 'soc', 'status', True)
with open('pmic.yaml', "r") as file:
data = load(file, Loader=Loader)
handle_soc_pmic(data, 'pmic', 'pmic', False)