# Path: harpoon/ship/progress_stream.py
# class Failure(Exception):
#     pass
# 
# class Unknown(Exception):
#     pass
# 
# Path: harpoon/ship/builders/base.py
# class BuilderBase(object):
#     def log_context_size(self, context, conf):
#         context_size = humanize.naturalsize(os.stat(context.name).st_size)
#         log.info(
#             "Building '%s' in '%s' with %s of context",
#             conf.name,
#             conf.context.parent_dir,
#             context_size,
#         )
# 
#     @contextmanager
#     def remove_replaced_images(self, conf):
#         tag = "latest" if conf.tag is sb.NotSpecified else conf.tag
#         image_name = "{0}:{1}".format(conf.image_name, tag)
# 
#         if not conf.harpoon.keep_replaced:
#             try:
#                 current_id = conf.harpoon.docker_api.inspect_image(image_name)["Id"]
#             except docker.errors.APIError as error:
#                 if str(error).startswith("404 Client Error: Not Found"):
#                     current_id = None
#                 else:
#                     raise
# 
#         info = {"cached": False}
#         yield info
# 
#         if current_id and not info.get("cached"):
#             log.info("Looking for replaced images to remove")
#             untagged = [
#                 image["Id"] for image in conf.harpoon.docker_api.images(filters={"dangling": True})
#             ]
#             if current_id in untagged:
#                 log.info(
#                     "Deleting replaced image\ttag=%s\told_hash=%s",
#                     "{0}".format(image_name),
#                     current_id,
#                 )
#                 try:
#                     conf.harpoon.docker_api.remove_image(current_id)
#                 except Exception as error:
#                     log.error(
#                         "Failed to remove replaced image\thash=%s\terror=%s", current_id, error
#                     )
# 
# Path: harpoon/errors.py
# class FailedImage(HarpoonError):
#     desc = "Something about an image failed"
# 
# Path: harpoon/helpers.py
# def a_temp_file():
# def until(timeout=10, step=0.5, action=None, silent=False):
#     def __init__(self, func):
#     def __get__(self, instance=None, owner=None):
#     def __set__(self, instance, value):
#     def __delete__(self, instance):
# def write_to(output, txt):
# class memoized_property(object):


from harpoon.ship.progress_stream import Failure, Unknown
from harpoon.ship.builders.base import BuilderBase
from harpoon.errors import FailedImage
from harpoon import helpers as hp
from itertools import chain
import logging

                if dep not in current_tags:
                    conf.login(dep, is_pushing=False)

        cache_from = list(conf.cache_from_names)
        if cache_from:
            log.info(
                "Using cache from the following images\timages={0}".format(", ".join(cache_from))
            )

        lines = conf.harpoon.docker_api.build(
            tag=image_name,
            fileobj=context.tmpfile,
            custom_context=True,
            cache_from=list(conf.cache_from_names),
            rm=True,
            pull=False,
        )

        for found in lines:
            for line in found.decode().split("\n"):
                if line.strip():
                    try:
                        stream.feed(line.encode())
                    except Failure as error:
                        raise FailedImage("Failed to build an image", image=conf.name, msg=error)
                    except Unknown as error:
                        log.warning("Unknown line\tline=%s", error)

                    for part in stream.printable():

# Path: harpoon/ship/progress_stream.py
# class Failure(Exception):
#     pass
# 
# class Unknown(Exception):
#     pass
# 
# Path: harpoon/ship/builders/base.py
# class BuilderBase(object):
#     def log_context_size(self, context, conf):
#         context_size = humanize.naturalsize(os.stat(context.name).st_size)
#         log.info(
#             "Building '%s' in '%s' with %s of context",
#             conf.name,
#             conf.context.parent_dir,
#             context_size,
#         )
# 
#     @contextmanager
#     def remove_replaced_images(self, conf):
#         tag = "latest" if conf.tag is sb.NotSpecified else conf.tag
#         image_name = "{0}:{1}".format(conf.image_name, tag)
# 
#         if not conf.harpoon.keep_replaced:
#             try:
#                 current_id = conf.harpoon.docker_api.inspect_image(image_name)["Id"]
#             except docker.errors.APIError as error:
#                 if str(error).startswith("404 Client Error: Not Found"):
#                     current_id = None
#                 else:
#                     raise
# 
#         info = {"cached": False}
#         yield info
# 
#         if current_id and not info.get("cached"):
#             log.info("Looking for replaced images to remove")
#             untagged = [
#                 image["Id"] for image in conf.harpoon.docker_api.images(filters={"dangling": True})
#             ]
#             if current_id in untagged:
#                 log.info(
#                     "Deleting replaced image\ttag=%s\told_hash=%s",
#                     "{0}".format(image_name),
#                     current_id,
#                 )
#                 try:
#                     conf.harpoon.docker_api.remove_image(current_id)
#                 except Exception as error:
#                     log.error(
#                         "Failed to remove replaced image\thash=%s\terror=%s", current_id, error
#                     )
# 
# Path: harpoon/errors.py
# class FailedImage(HarpoonError):
#     desc = "Something about an image failed"
# 
# Path: harpoon/helpers.py
# def a_temp_file():
# def until(timeout=10, step=0.5, action=None, silent=False):
#     def __init__(self, func):
#     def __get__(self, instance=None, owner=None):
#     def __set__(self, instance, value):
#     def __delete__(self, instance):
# def write_to(output, txt):
# class memoized_property(object):


# Path: harpoon/ship/builders/normal.py
from harpoon.ship.progress_stream import Failure, Unknown
from harpoon.ship.builders.base import BuilderBase
from harpoon.errors import FailedImage
from harpoon import helpers as hp
from itertools import chain
import logging


                if dep not in current_tags:
                    conf.login(dep, is_pushing=False)

        cache_from = list(conf.cache_from_names)
        if cache_from:
            log.info(
                "Using cache from the following images\timages={0}".format(", ".join(cache_from))
            )

        lines = conf.harpoon.docker_api.build(
            tag=image_name,
            fileobj=context.tmpfile,
            custom_context=True,
            cache_from=list(conf.cache_from_names),
            rm=True,
            pull=False,
        )

        for found in lines:
            for line in found.decode().split("\n"):
                if line.strip():
                    try:
                        stream.feed(line.encode())
                    except Failure as error:
                        raise FailedImage("Failed to build an image", image=conf.name, msg=error)
                    except Unknown as error:
                        log.warning("Unknown line\tline=%s", error)

                    for part in stream.printable():

                        hp.write_to(conf.harpoon.stdout, part)