39 lines
941 B
Python
39 lines
941 B
Python
import json
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
import sys
|
|
|
|
|
|
def build_modem_env(modem):
|
|
with open('render-params.json') as f:
|
|
config = json.load(f)
|
|
if modem not in config['modem_types']:
|
|
raise RuntimeError(f"Modem '{modem}' is not exist in config!")
|
|
|
|
mc = config['modem_types'][modem]
|
|
|
|
return {
|
|
"modem_name": mc['modem_name'],
|
|
"header_tabs": mc['tabs'],
|
|
"js_tabs_array": str([t['name'] for t in mc['tabs']])
|
|
}
|
|
|
|
|
|
def render_modem(modem):
|
|
loader = FileSystemLoader('template')
|
|
env = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True)
|
|
template = env.get_template('main.html')
|
|
|
|
context = build_modem_env(modem)
|
|
|
|
with open(f"main-{modem}.html", "w") as f:
|
|
f.write(template.render(context))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) != 2:
|
|
print(f"Usage: {sys.argv[0]} <scpc|tdma>")
|
|
|
|
render_modem(sys.argv[1])
|
|
|