# Path: harpoon/errors.py
# class HarpoonError(DelfickError):
#     pass
# 
# class BadOption(HarpoonError):
#     desc = "Bad Option"
# 
# Path: harpoon/helpers.py
# @contextmanager
# def a_temp_file():
#     """Yield the name of a temporary file and ensure it's removed after use"""
#     filename = None
#     try:
#         tmpfile = tempfile.NamedTemporaryFile(delete=False)
#         filename = tmpfile.name
#         yield tmpfile
#     finally:
#         if filename and os.path.exists(filename):
#             os.remove(filename)


from harpoon.errors import HarpoonError, BadOption
from harpoon.helpers import a_temp_file
from contextlib import contextmanager
from io import BytesIO
            from harpoon.ship.runner import Runner, ContainerRunner
import subprocess
import tempfile
import tarfile
import fnmatch
import logging
import shutil
import docker
import shlex
import os
import re
            If True, then suppress printing out information

        extra_context - List of (content, string)
            content is either a string repsenting the content to put in a file
            or a dictionary representing what path to get from what docker image

            The second string represents where in the context this extra file should go
        """
        with a_temp_file() as tmpfile:
            t = tarfile.open(mode="w", fileobj=tmpfile)
            for thing, arcname in self.find_files_for_tar(context, silent_build):
                log.debug("Context: {0}".format(arcname))
                t.add(thing, arcname=arcname)

            if extra_context:
                extra = list(extra_context)
                for content, arcname in extra:
                    if arcname == "":
                        continue

                    with self.the_context(content, silent_build=silent_build) as fle:
                        log.debug("Context: {0}".format(arcname))
                        t.add(fle.name, arcname=arcname)

            yield ContextWrapper(t, tmpfile)

    @contextmanager
    def the_context(self, content, silent_build=False):
        """Return either a file with the content written to it, or a whole new context tar"""
        if isinstance(content, str):

# Path: harpoon/errors.py
# class HarpoonError(DelfickError):
#     pass
# 
# class BadOption(HarpoonError):
#     desc = "Bad Option"
# 
# Path: harpoon/helpers.py
# @contextmanager
# def a_temp_file():
#     """Yield the name of a temporary file and ensure it's removed after use"""
#     filename = None
#     try:
#         tmpfile = tempfile.NamedTemporaryFile(delete=False)
#         filename = tmpfile.name
#         yield tmpfile
#     finally:
#         if filename and os.path.exists(filename):
#             os.remove(filename)


# Path: harpoon/ship/context.py
from harpoon.errors import HarpoonError, BadOption
from harpoon.helpers import a_temp_file
from contextlib import contextmanager
from io import BytesIO
            from harpoon.ship.runner import Runner, ContainerRunner
import subprocess
import tempfile
import tarfile
import fnmatch
import logging
import shutil
import docker
import shlex
import os
import re

            If True, then suppress printing out information

        extra_context - List of (content, string)
            content is either a string repsenting the content to put in a file
            or a dictionary representing what path to get from what docker image

            The second string represents where in the context this extra file should go
        """
        with a_temp_file() as tmpfile:
            t = tarfile.open(mode="w", fileobj=tmpfile)
            for thing, arcname in self.find_files_for_tar(context, silent_build):
                log.debug("Context: {0}".format(arcname))
                t.add(thing, arcname=arcname)

            if extra_context:
                extra = list(extra_context)
                for content, arcname in extra:
                    if arcname == "":
                        continue

                    with self.the_context(content, silent_build=silent_build) as fle:
                        log.debug("Context: {0}".format(arcname))
                        t.add(fle.name, arcname=arcname)

            yield ContextWrapper(t, tmpfile)

    @contextmanager
    def the_context(self, content, silent_build=False):
        """Return either a file with the content written to it, or a whole new context tar"""
        if isinstance(content, str):

            with a_temp_file() as fle: