Files
op25-docker/app/internal/liquidsoap_config_utils.py
Logan Cusano 1392c8b244
Some checks failed
Lint / lint (push) Failing after 54s
release-tag / release-image (push) Has been cancelled
Generate new op25.liq each time we change the config + mini fixes
2025-10-23 02:39:22 -04:00

34 lines
1.3 KiB
Python

import os
from internal.op25.liq_template import liquidsoap_config_template
from models import IcecastConfig
def generate_liquid_script(config: IcecastConfig):
"""
Generates the "*.liq" file that's run by OP25 on startup.
Placeholders in the template must be formatted as ${VARIABLE_NAME}.
Args:
config (dict): A dictionary of key-value pairs for substitution.
Keys should match the variable names in the template (e.g., 'icecast_host').
"""
try:
content = liquidsoap_config_template
# Replace variables
for key, value in config.items():
placeholder = f"${{{key}}}"
# Ensure the value is converted to string for replacement
content = content.replace(placeholder, str(value))
print(f" - Replaced placeholder {placeholder}")
# Write the processed content to the output path
output_path = "/op25/op25/gr-op25_repeater/apps/op25.liq"
with open(output_path, 'w') as f:
f.write(content)
print(f"\nSuccessfully wrote processed configuration to: {output_path}")
except FileNotFoundError:
print(f"Error: Template file not found at {template_path}")
except Exception as e:
print(f"An unexpected error occurred: {e}")