refactor(playout): generate entrypoint to string

This commit is contained in:
jo 2023-03-01 17:59:27 +01:00 committed by Kyle Robbertze
parent f09d0ec3c6
commit c6c5b1125f
3 changed files with 32 additions and 36 deletions

View File

@ -18,13 +18,12 @@ templates.filters["quote"] = quote
def generate_entrypoint(
entrypoint_filepath: Path,
log_filepath: Optional[Path],
config: Config,
preferences: StreamPreferences,
info: Info,
version: Tuple[int, int, int],
):
) -> str:
paths = {}
paths["auth_filepath"] = here / "liquidsoap_auth.py"
paths["lib_filepath"] = here / f"{version[0]}.{version[1]}/ls_script.liq"
@ -32,13 +31,10 @@ def generate_entrypoint(
if log_filepath is not None:
paths["log_filepath"] = log_filepath.resolve()
entrypoint_filepath.write_text(
templates.get_template("entrypoint.liq.j2").render(
config=config.copy(),
preferences=preferences,
info=info,
paths=paths,
version=version,
),
encoding="utf-8",
return templates.get_template("entrypoint.liq.j2").render(
config=config.copy(),
preferences=preferences,
info=info,
paths=paths,
version=version,
)

View File

@ -40,13 +40,15 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
preferences = StreamPreferences(**api_client.get_stream_preferences().json())
entrypoint_filepath = Path.cwd() / "radio.liq"
generate_entrypoint(
entrypoint_filepath,
log_filepath,
config,
preferences,
info,
version,
entrypoint_filepath.write_text(
generate_entrypoint(
log_filepath,
config,
preferences,
info,
version,
),
encoding="utf-8",
)
exec_args = [

View File

@ -21,15 +21,12 @@ from .fixtures import TEST_STREAM_CONFIGS
"stream_config",
TEST_STREAM_CONFIGS,
)
def test_generate_entrypoint(tmp_path: Path, stream_config: Config, version, snapshot):
entrypoint_filepath = tmp_path / "radio.liq"
def test_generate_entrypoint(stream_config: Config, version, snapshot):
with mock.patch(
"libretime_playout.liquidsoap.entrypoint.here",
Path("/fake"),
):
generate_entrypoint(
entrypoint_filepath,
found = generate_entrypoint(
log_filepath=Path("/var/log/radio.log"),
config=stream_config,
preferences=StreamPreferences(
@ -43,7 +40,6 @@ def test_generate_entrypoint(tmp_path: Path, stream_config: Config, version, sna
version=version,
)
found = entrypoint_filepath.read_text(encoding="utf-8")
assert found == snapshot
@ -59,19 +55,21 @@ def test_liquidsoap_syntax(tmp_path: Path, stream_config):
entrypoint_filepath = tmp_path / "radio.liq"
log_filepath = tmp_path / "radio.log"
generate_entrypoint(
entrypoint_filepath,
log_filepath=log_filepath,
config=stream_config,
preferences=StreamPreferences(
input_fade_transition=0.0,
message_format=0,
message_offline="LibreTime - offline",
entrypoint_filepath.write_text(
generate_entrypoint(
log_filepath=log_filepath,
config=stream_config,
preferences=StreamPreferences(
input_fade_transition=0.0,
message_format=0,
message_offline="LibreTime - offline",
),
info=Info(
station_name="LibreTime",
),
version=get_liquidsoap_version(),
),
info=Info(
station_name="LibreTime",
),
version=get_liquidsoap_version(),
encoding="utf-8",
)
check_call(["liquidsoap", "--check", str(entrypoint_filepath)])