# 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
        code = 0
    except subprocess.CalledProcessError as error:
        output = error.output
        code = error.returncode

    lines = [line for line in output.decode().split("\n") if line.strip()]
    return lines, code


class ContextWrapper(object):
    """Wraps a tarfile context, so we can continue changing it afterwards"""

    def __init__(self, t, tmpfile):
        self.t = t
        self.tmpfile = tmpfile

    def close(self):
        self.t.close()
        self.tmpfile.flush()
        self.tmpfile.seek(0)

    @property
    def name(self):
        return self.tmpfile.name

    @contextmanager
    def clone_with_new_dockerfile(self, conf, docker_file):
        """Clone this tarfile and add in another filename before closing the new tar and returning"""
        log.info("Copying context to add a different dockerfile")
        self.close()

# 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

        code = 0
    except subprocess.CalledProcessError as error:
        output = error.output
        code = error.returncode

    lines = [line for line in output.decode().split("\n") if line.strip()]
    return lines, code


class ContextWrapper(object):
    """Wraps a tarfile context, so we can continue changing it afterwards"""

    def __init__(self, t, tmpfile):
        self.t = t
        self.tmpfile = tmpfile

    def close(self):
        self.t.close()
        self.tmpfile.flush()
        self.tmpfile.seek(0)

    @property
    def name(self):
        return self.tmpfile.name

    @contextmanager
    def clone_with_new_dockerfile(self, conf, docker_file):
        """Clone this tarfile and add in another filename before closing the new tar and returning"""
        log.info("Copying context to add a different dockerfile")
        self.close()

        with a_temp_file() as tmpfile: