# 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
                        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:
                fle.write(content.encode("utf-8"))
                fle.seek(0)
                yield fle
        elif "context" in content:
            with ContextBuilder().make_context(
                content["context"], silent_build=silent_build
            ) as wrapper:
                wrapper.close()
                yield wrapper.tmpfile
        elif "image" in content:

            with a_temp_file() as fle:
                content["conf"].command = "yes"
                with ContainerRunner(
                    Runner(), content["conf"], content["images"], detach=True, delete_anyway=True
                ):
                    try:
                        strm, stat = content["docker_api"].get_archive(
                            content["conf"].container_id, content["path"]
                        )
                    except docker.errors.NotFound:

# 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

                        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:
                fle.write(content.encode("utf-8"))
                fle.seek(0)
                yield fle
        elif "context" in content:
            with ContextBuilder().make_context(
                content["context"], silent_build=silent_build
            ) as wrapper:
                wrapper.close()
                yield wrapper.tmpfile
        elif "image" in content:

            with a_temp_file() as fle:
                content["conf"].command = "yes"
                with ContainerRunner(
                    Runner(), content["conf"], content["images"], detach=True, delete_anyway=True
                ):
                    try:
                        strm, stat = content["docker_api"].get_archive(
                            content["conf"].container_id, content["path"]
                        )
                    except docker.errors.NotFound:

                        raise BadOption(