from ...objects.config import Config
from ...objects.job import Job

import os

FILE_PATH = "{path}/.dockerignore"

# Builds the dockerignore based on the config
def buildDockerignore(config):

    # Setup the basics of all dockerignores
    docker  = "# This dockerignore was generated by Skelebot\n"
    docker += "# Editing this file manually is not advised as all changes will be overwritten during Skelebot execution\n"

    # Add the base level ignores for the project defined in the yaml
    for ignore in config.ignores:
        docker += "{ignore}\n".format(ignore=ignore)

    # Pull in any additional dockerignore updates from the components
    for component in config.components:
        docker += component.appendDockerignore()

    dockerignore = open(FILE_PATH.format(path=os.getcwd()), "w")
    dockerignore.write(docker)
    dockerignore.close()
