refactor(playout): generate entrypoint to string
This commit is contained in:
parent
f09d0ec3c6
commit
c6c5b1125f
|
@ -18,13 +18,12 @@ templates.filters["quote"] = quote
|
||||||
|
|
||||||
|
|
||||||
def generate_entrypoint(
|
def generate_entrypoint(
|
||||||
entrypoint_filepath: Path,
|
|
||||||
log_filepath: Optional[Path],
|
log_filepath: Optional[Path],
|
||||||
config: Config,
|
config: Config,
|
||||||
preferences: StreamPreferences,
|
preferences: StreamPreferences,
|
||||||
info: Info,
|
info: Info,
|
||||||
version: Tuple[int, int, int],
|
version: Tuple[int, int, int],
|
||||||
):
|
) -> str:
|
||||||
paths = {}
|
paths = {}
|
||||||
paths["auth_filepath"] = here / "liquidsoap_auth.py"
|
paths["auth_filepath"] = here / "liquidsoap_auth.py"
|
||||||
paths["lib_filepath"] = here / f"{version[0]}.{version[1]}/ls_script.liq"
|
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:
|
if log_filepath is not None:
|
||||||
paths["log_filepath"] = log_filepath.resolve()
|
paths["log_filepath"] = log_filepath.resolve()
|
||||||
|
|
||||||
entrypoint_filepath.write_text(
|
return templates.get_template("entrypoint.liq.j2").render(
|
||||||
templates.get_template("entrypoint.liq.j2").render(
|
config=config.copy(),
|
||||||
config=config.copy(),
|
preferences=preferences,
|
||||||
preferences=preferences,
|
info=info,
|
||||||
info=info,
|
paths=paths,
|
||||||
paths=paths,
|
version=version,
|
||||||
version=version,
|
|
||||||
),
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -40,13 +40,15 @@ def cli(log_level: str, log_filepath: Optional[Path], config_filepath: Optional[
|
||||||
preferences = StreamPreferences(**api_client.get_stream_preferences().json())
|
preferences = StreamPreferences(**api_client.get_stream_preferences().json())
|
||||||
|
|
||||||
entrypoint_filepath = Path.cwd() / "radio.liq"
|
entrypoint_filepath = Path.cwd() / "radio.liq"
|
||||||
generate_entrypoint(
|
entrypoint_filepath.write_text(
|
||||||
entrypoint_filepath,
|
generate_entrypoint(
|
||||||
log_filepath,
|
log_filepath,
|
||||||
config,
|
config,
|
||||||
preferences,
|
preferences,
|
||||||
info,
|
info,
|
||||||
version,
|
version,
|
||||||
|
),
|
||||||
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
exec_args = [
|
exec_args = [
|
||||||
|
|
|
@ -21,15 +21,12 @@ from .fixtures import TEST_STREAM_CONFIGS
|
||||||
"stream_config",
|
"stream_config",
|
||||||
TEST_STREAM_CONFIGS,
|
TEST_STREAM_CONFIGS,
|
||||||
)
|
)
|
||||||
def test_generate_entrypoint(tmp_path: Path, stream_config: Config, version, snapshot):
|
def test_generate_entrypoint(stream_config: Config, version, snapshot):
|
||||||
entrypoint_filepath = tmp_path / "radio.liq"
|
|
||||||
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"libretime_playout.liquidsoap.entrypoint.here",
|
"libretime_playout.liquidsoap.entrypoint.here",
|
||||||
Path("/fake"),
|
Path("/fake"),
|
||||||
):
|
):
|
||||||
generate_entrypoint(
|
found = generate_entrypoint(
|
||||||
entrypoint_filepath,
|
|
||||||
log_filepath=Path("/var/log/radio.log"),
|
log_filepath=Path("/var/log/radio.log"),
|
||||||
config=stream_config,
|
config=stream_config,
|
||||||
preferences=StreamPreferences(
|
preferences=StreamPreferences(
|
||||||
|
@ -43,7 +40,6 @@ def test_generate_entrypoint(tmp_path: Path, stream_config: Config, version, sna
|
||||||
version=version,
|
version=version,
|
||||||
)
|
)
|
||||||
|
|
||||||
found = entrypoint_filepath.read_text(encoding="utf-8")
|
|
||||||
assert found == snapshot
|
assert found == snapshot
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,19 +55,21 @@ def test_liquidsoap_syntax(tmp_path: Path, stream_config):
|
||||||
entrypoint_filepath = tmp_path / "radio.liq"
|
entrypoint_filepath = tmp_path / "radio.liq"
|
||||||
log_filepath = tmp_path / "radio.log"
|
log_filepath = tmp_path / "radio.log"
|
||||||
|
|
||||||
generate_entrypoint(
|
entrypoint_filepath.write_text(
|
||||||
entrypoint_filepath,
|
generate_entrypoint(
|
||||||
log_filepath=log_filepath,
|
log_filepath=log_filepath,
|
||||||
config=stream_config,
|
config=stream_config,
|
||||||
preferences=StreamPreferences(
|
preferences=StreamPreferences(
|
||||||
input_fade_transition=0.0,
|
input_fade_transition=0.0,
|
||||||
message_format=0,
|
message_format=0,
|
||||||
message_offline="LibreTime - offline",
|
message_offline="LibreTime - offline",
|
||||||
|
),
|
||||||
|
info=Info(
|
||||||
|
station_name="LibreTime",
|
||||||
|
),
|
||||||
|
version=get_liquidsoap_version(),
|
||||||
),
|
),
|
||||||
info=Info(
|
encoding="utf-8",
|
||||||
station_name="LibreTime",
|
|
||||||
),
|
|
||||||
version=get_liquidsoap_version(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
check_call(["liquidsoap", "--check", str(entrypoint_filepath)])
|
check_call(["liquidsoap", "--check", str(entrypoint_filepath)])
|
||||||
|
|
Loading…
Reference in New Issue