# Path: shipwright/_lib/base.py
# class Shipwright(object):
#     def __init__(self, source_control, docker_client, tags, cache):
#         self.source_control = source_control
#         self.docker_client = docker_client
#         self.tags = tags
#         self._cache = cache
# 
#     def targets(self):
#         return self.source_control.targets()
# 
#     def build(self, build_targets):
#         targets = dependencies.eval(build_targets, self.targets())
#         this_ref_str = self.source_control.this_ref_str()
#         return self._build(this_ref_str, targets)
# 
#     def _build(self, this_ref_str, targets):
#         client = self.docker_client
#         ref = this_ref_str
#         tags = self.source_control.default_tags() + self.tags + [this_ref_str]
#         for evt in build.do_build(client, ref, targets, self._cache):
#             if isinstance(evt, BuildComplete):
#                 target = evt.target
#                 for tag_evt in self._cache.tag([target], tags):
#                     yield tag_evt
#             yield evt
# 
#     def images(self, build_targets):
#         for target in dependencies.eval(build_targets, self.targets()):
#             yield {
#                 'stream': '{t.name}:{t.ref}'.format(t=target),
#                 'event': 'log',
#             }
# 
#     def push(self, build_targets, no_build=False):
#         """
#         Pushes the latest images to the repository.
#         """
#         targets = dependencies.eval(build_targets, self.targets())
#         this_ref_str = self.source_control.this_ref_str()
#         tags = self.source_control.default_tags() + self.tags + [this_ref_str]
# 
#         if no_build:
#             for evt in self._cache.push(targets, tags):
#                 yield evt
#             return
# 
#         for evt in self._build(this_ref_str, targets):
#             if isinstance(evt, BuildComplete):
#                 for push_evt in self._cache.push([evt.target], tags):
#                     yield push_evt
#             yield evt
# 
# Path: shipwright/_lib/msg.py
# class Message(object):
#     """
#     Base class for all other messages
#     """


import argparse
import collections
import json
import os
import re
import shlex
import sys
import docker
    import docker_registry_client as drc
from itertools import chain, cycle
from docker.utils import kwargs_from_env
from . import cache, registry, source_control
from .base import Shipwright
from .colors import rainbow
from .msg import Message
            raise drc

        registry_config = parse_registry_logins(registry_logins)
        registries = {}
        for server, config in registry_config.items():
            registries[server] = drc.BaseClient(
                config['server'],
                username=config['username'],
                password=config['password'],
                api_version=2,
            )
        the_cache = cache.DirectRegistry(client, registry.Registry(registries))
    elif pull_cache:
        the_cache = cache.Cache(client)
    else:
        the_cache = cache.NoCache(client)

    sw = Shipwright(scm, client, arguments['tags'], the_cache)
    command = getattr(sw, command_name)

    show_progress = sys.stdout.isatty()

    errors = []

    if no_build:
        events = command(build_targets, no_build)
    else:
        events = command(build_targets)

    for event in events:

# Path: shipwright/_lib/base.py
# class Shipwright(object):
#     def __init__(self, source_control, docker_client, tags, cache):
#         self.source_control = source_control
#         self.docker_client = docker_client
#         self.tags = tags
#         self._cache = cache
# 
#     def targets(self):
#         return self.source_control.targets()
# 
#     def build(self, build_targets):
#         targets = dependencies.eval(build_targets, self.targets())
#         this_ref_str = self.source_control.this_ref_str()
#         return self._build(this_ref_str, targets)
# 
#     def _build(self, this_ref_str, targets):
#         client = self.docker_client
#         ref = this_ref_str
#         tags = self.source_control.default_tags() + self.tags + [this_ref_str]
#         for evt in build.do_build(client, ref, targets, self._cache):
#             if isinstance(evt, BuildComplete):
#                 target = evt.target
#                 for tag_evt in self._cache.tag([target], tags):
#                     yield tag_evt
#             yield evt
# 
#     def images(self, build_targets):
#         for target in dependencies.eval(build_targets, self.targets()):
#             yield {
#                 'stream': '{t.name}:{t.ref}'.format(t=target),
#                 'event': 'log',
#             }
# 
#     def push(self, build_targets, no_build=False):
#         """
#         Pushes the latest images to the repository.
#         """
#         targets = dependencies.eval(build_targets, self.targets())
#         this_ref_str = self.source_control.this_ref_str()
#         tags = self.source_control.default_tags() + self.tags + [this_ref_str]
# 
#         if no_build:
#             for evt in self._cache.push(targets, tags):
#                 yield evt
#             return
# 
#         for evt in self._build(this_ref_str, targets):
#             if isinstance(evt, BuildComplete):
#                 for push_evt in self._cache.push([evt.target], tags):
#                     yield push_evt
#             yield evt
# 
# Path: shipwright/_lib/msg.py
# class Message(object):
#     """
#     Base class for all other messages
#     """


# Path: shipwright/_lib/cli.py
import argparse
import collections
import json
import os
import re
import shlex
import sys
import docker
    import docker_registry_client as drc
from itertools import chain, cycle
from docker.utils import kwargs_from_env
from . import cache, registry, source_control
from .base import Shipwright
from .colors import rainbow
from .msg import Message

            raise drc

        registry_config = parse_registry_logins(registry_logins)
        registries = {}
        for server, config in registry_config.items():
            registries[server] = drc.BaseClient(
                config['server'],
                username=config['username'],
                password=config['password'],
                api_version=2,
            )
        the_cache = cache.DirectRegistry(client, registry.Registry(registries))
    elif pull_cache:
        the_cache = cache.Cache(client)
    else:
        the_cache = cache.NoCache(client)

    sw = Shipwright(scm, client, arguments['tags'], the_cache)
    command = getattr(sw, command_name)

    show_progress = sys.stdout.isatty()

    errors = []

    if no_build:
        events = command(build_targets, no_build)
    else:
        events = command(build_targets)

    for event in events:

        if isinstance(event, Message):