2022-01-13 16:11:37 +01:00
|
|
|
from pathlib import Path
|
2022-08-10 17:33:22 +02:00
|
|
|
from typing import Optional, Tuple
|
2021-06-03 15:20:39 +02:00
|
|
|
|
2023-02-25 16:05:59 +01:00
|
|
|
from jinja2 import Environment, PackageLoader
|
2012-05-29 00:48:40 +02:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
from ..config import Config
|
|
|
|
from .models import Info, StreamPreferences
|
2023-02-20 16:00:48 +01:00
|
|
|
from .utils import quote
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
here = Path(__file__).parent
|
2012-07-16 21:34:09 +02:00
|
|
|
|
2023-02-25 16:05:59 +01:00
|
|
|
templates_loader = PackageLoader(__name__, "templates")
|
2023-02-20 15:57:36 +01:00
|
|
|
templates = Environment( # nosec
|
|
|
|
loader=templates_loader,
|
2022-08-10 17:33:22 +02:00
|
|
|
keep_trailing_newline=True,
|
|
|
|
)
|
2023-02-20 16:00:48 +01:00
|
|
|
templates.filters["quote"] = quote
|
2012-07-16 21:34:09 +02:00
|
|
|
|
2020-01-23 11:37:49 +01:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
def generate_entrypoint(
|
|
|
|
log_filepath: Optional[Path],
|
|
|
|
config: Config,
|
|
|
|
preferences: StreamPreferences,
|
|
|
|
info: Info,
|
|
|
|
version: Tuple[int, int, int],
|
2023-03-01 17:59:27 +01:00
|
|
|
) -> str:
|
2022-08-10 17:33:22 +02:00
|
|
|
paths = {}
|
|
|
|
paths["lib_filepath"] = here / f"{version[0]}.{version[1]}/ls_script.liq"
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2022-08-10 17:33:22 +02:00
|
|
|
if log_filepath is not None:
|
|
|
|
paths["log_filepath"] = log_filepath.resolve()
|
2020-01-23 11:37:49 +01:00
|
|
|
|
2023-03-01 17:59:27 +01:00
|
|
|
return templates.get_template("entrypoint.liq.j2").render(
|
2023-12-28 14:19:29 +01:00
|
|
|
config=config.model_copy(),
|
2023-03-01 17:59:27 +01:00
|
|
|
preferences=preferences,
|
|
|
|
info=info,
|
|
|
|
paths=paths,
|
|
|
|
version=version,
|
2022-08-10 17:33:22 +02:00
|
|
|
)
|