def adapt_scen_template_to_sources(open_file, source_names):
    """
    Adapts the scenario template to the current sources. In particular, the set
    'NondispatchableGeneratorsAtBus' is filled with the sources' names.

    Args:
        open_file (file): the open template file
        source_names (list[str]): a list of all source names

    Returns:
        str: a string with the adapted template
    """

    output = ""
    for line in open_file:
        if line.startswith('set NondispatchableGeneratorsAtBus'):
            split_line = line.split(':=')
            adapted_line = split_line[0] + ':= ' + " ".join(source_names) + " ;\n"
            output += adapted_line
        else:
            output += line

    return output