Skip to content

template_utils

load_template_configuration_as_dic(template_configuration_name)

Load a template configuration as a dictionary.

Parameters:

Name Type Description Default
template_configuration_name str

The name of the template configuration.

required

Returns:

Name Type Description
dict tuple[dict, YAML]

The template dictionary.

Source code in study_da/utils/template_utils.py
def load_template_configuration_as_dic(
    template_configuration_name: str,
) -> tuple[dict, ruamel.yaml.YAML]:
    """Load a template configuration as a dictionary.

    Args:
        template_configuration_name (str): The name of the template configuration.

    Returns:
        dict: The template dictionary.

    """
    path_local_template_configurations = (
        f"{os.path.dirname(inspect.getfile(GenerateScan))}/../assets/configurations/"
    )

    # Add .yaml extension to template name
    if not template_configuration_name.endswith(".yaml"):
        template_configuration_name = f"{template_configuration_name}.yaml"

    # Get path to template
    path_template_config = f"{path_local_template_configurations}{template_configuration_name}"

    # Load template
    return load_dic_from_path(path_template_config)

load_template_script_as_str(template_script_name)

Load a template script as a string.

Parameters:

Name Type Description Default
template_script_name str

The name of the template script.

required

Returns:

Name Type Description
str str

The template script as a string.

Source code in study_da/utils/template_utils.py
def load_template_script_as_str(template_script_name: str) -> str:
    """Load a template script as a string.

    Args:
        template_script_name (str): The name of the template script.

    Returns:
        str: The template script as a string.

    """
    path_local_template_scripts = (
        f"{os.path.dirname(inspect.getfile(GenerateScan))}/../assets/template_scripts/"
    )

    # Get path to template
    path_template_script = f"{path_local_template_scripts}{template_script_name}"

    # Load template
    with open(path_template_script, "r") as fid:
        template_script = fid.read()

    return template_script