summaryrefslogtreecommitdiff
path: root/buildscripts/task_generation/generated_config.py
blob: c054648bcbb08d6d5edfd9183cce1210026b630b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Generated configuration."""
from typing import NamedTuple, List

from buildscripts.util.fileops import write_file_to_dir


class GeneratedFile(NamedTuple):
    """
    Generated configuration file.

    file_name: Name of generated configuration.
    content: Content of generated configuration.
    """

    file_name: str
    content: str

    def write_to_dir(self, directory: str) -> None:
        """
        Write this file to the given directory.

        :param directory: Directory to write file to.
        """
        write_file_to_dir(directory, self.file_name, self.content, overwrite=False)


class GeneratedConfiguration(NamedTuple):
    """
    Contain for the configuration needed to generate a task.

    file_list: List of filenames and file contents needed to generate a task.
    """

    file_list: List[GeneratedFile]

    def write_all_to_dir(self, directory: str) -> None:
        """
        Write all the configuration files to the given directory.

        :param directory: Directory to write to.
        """
        for item in self.file_list:
            item.write_to_dir(directory)