# Path: harpoon/actions.py
# class an_action(object):
#     def __init__(self, needs_image=False):
#     def __call__(self, func):
# def push(collector, image, **kwargs):
# def push_all(collector, **kwargs):
# def pull_arbitrary(collector, image, **kwargs):
# def pull(collector, image, **kwargs):
# def pull_dependencies(collector, image, **kwargs):
# def pull_parent(collector, image, **kwargs):
# def pull_all(collector, image, **kwargs):
# def pull_all_external(collector, **kwargs):
# def pull_parents(collector, **kwargs):
# def make(collector, image, **kwargs):
# def make_all(collector, **kwargs):
# def make_pushable(collector, **kwargs):
# def run(collector, image, **kwargs):
# def list_tasks(collector, tasks, **kwargs):
# def delete_untagged(collector, **kwargs):
# def show(collector, **kwargs):
# def show_pushable(collector, **kwargs):
# def print_dockerfile(collector, image, **kwargs):
# def get_docker_context(collector, image, **kwargs):
# def print_all_dockerfiles(collector, **kwargs):
# def read_login(collector, image, **kwargs):
# def write_login(collector, image, **kwargs):
# def untag(collector, image, artifact, **kwargs):
# def tag(collector, image, artifact, **kwargs):
# def retrieve(collector, image, artifact, **kwargs):
# def container_manager(collector, image, **kwargs):
#     def shutdown(signum, frame):
# 
# Path: harpoon/option_spec/task_objs.py
# class Task(dictobj):
#     """
#     Used to add extra options associated with the task and to start the action
#     from ``harpoon.actions``.
# 
#     Also responsible for complaining if the specified action doesn't exist.
# 
#     Will also ask the image to complain about any missing environment variables.
#     """
# 
#     fields = {
#         ("action", "run"): "The action to run with this image",
#         ("options", None): "The options to merge with the image options",
#         ("overrides", None): "The options to merge with the root configuration",
#         ("description", ""): "The description of the task",
#         ("label", "Project"): "The namespace when listing tasks",
#     }
# 
#     def setup(self, *args, **kwargs):
#         super(Task, self).setup(*args, **kwargs)
#         self.set_description()
# 
#     def set_description(self, available_actions=None):
#         if not self.description:
#             if not available_actions:
#                 from harpoon.actions import available_actions
#             if self.action in available_actions:
#                 self.description = available_actions[self.action].__doc__
# 
#     def run(self, collector, image, available_actions, tasks, **extras):
#         """Run this task"""
#         task_func = available_actions[self.action]
#         configuration = collector.configuration.wrapped()
# 
#         if self.options:
#             if image:
#                 configuration.update({"images": {image: self.options}})
#             else:
#                 configuration.update(self.options)
# 
#         # args like --port and the like should override what's in the options
#         # But themselves be overridden by the overrides
#         configuration.update(configuration["args_dict"].as_dict(), source="<args_dict>")
# 
#         if self.overrides:
#             overrides = {}
#             for key, val in self.overrides.items():
#                 overrides[key] = val
#                 if isinstance(val, MergedOptions):
#                     overrides[key] = dict(val.items())
#             configuration.update(overrides)
# 
#         if task_func.needs_image:
#             self.find_image(image, configuration)
#             image = configuration["images"][image]
#             image.find_missing_env()
# 
#         from harpoon.collector import Collector
# 
#         new_collector = Collector()
#         new_collector.configuration = configuration
#         new_collector.configuration_file = collector.configuration_file
#         artifact = configuration["harpoon"].artifact
#         return task_func(new_collector, image=image, tasks=tasks, artifact=artifact, **extras)
# 
#     def find_image(self, image, configuration):
#         """Complain if we don't have an image"""
#         images = configuration["images"]
#         available = list(images.keys())
# 
#         if not image:
#             info = {}
#             if available:
#                 info["available"] = available
#             raise BadOption("Please use --image to specify an image", **info)
# 
#         if image not in images:
#             raise BadOption("No such image", wanted=image, available=available)
# 
# Path: harpoon/errors.py
# class BadTask(HarpoonError):
#     desc = "Bad task"


from harpoon.actions import available_actions, default_actions
from harpoon.option_spec.task_objs import Task
from harpoon.errors import BadTask
"""
Responsible for finding tasks in the configuration and executing them
"""



class TaskFinder(object):
    def __init__(self, collector):
        self.tasks = {}
        self.collector = collector

    def image_finder(self, task):
        return getattr(
            self.tasks[task], "image", self.collector.configuration["harpoon"].chosen_image
        )

    def task_runner(self, task, **kwargs):
        if task not in self.tasks:
            raise BadTask("Unknown task", task=task, available=sorted(list(self.tasks.keys())))
        return self.tasks[task].run(
            self.collector, self.image_finder(task), available_actions, self.tasks, **kwargs
        )

    def default_tasks(self):
        """Return default tasks"""

# Path: harpoon/actions.py
# class an_action(object):
#     def __init__(self, needs_image=False):
#     def __call__(self, func):
# def push(collector, image, **kwargs):
# def push_all(collector, **kwargs):
# def pull_arbitrary(collector, image, **kwargs):
# def pull(collector, image, **kwargs):
# def pull_dependencies(collector, image, **kwargs):
# def pull_parent(collector, image, **kwargs):
# def pull_all(collector, image, **kwargs):
# def pull_all_external(collector, **kwargs):
# def pull_parents(collector, **kwargs):
# def make(collector, image, **kwargs):
# def make_all(collector, **kwargs):
# def make_pushable(collector, **kwargs):
# def run(collector, image, **kwargs):
# def list_tasks(collector, tasks, **kwargs):
# def delete_untagged(collector, **kwargs):
# def show(collector, **kwargs):
# def show_pushable(collector, **kwargs):
# def print_dockerfile(collector, image, **kwargs):
# def get_docker_context(collector, image, **kwargs):
# def print_all_dockerfiles(collector, **kwargs):
# def read_login(collector, image, **kwargs):
# def write_login(collector, image, **kwargs):
# def untag(collector, image, artifact, **kwargs):
# def tag(collector, image, artifact, **kwargs):
# def retrieve(collector, image, artifact, **kwargs):
# def container_manager(collector, image, **kwargs):
#     def shutdown(signum, frame):
# 
# Path: harpoon/option_spec/task_objs.py
# class Task(dictobj):
#     """
#     Used to add extra options associated with the task and to start the action
#     from ``harpoon.actions``.
# 
#     Also responsible for complaining if the specified action doesn't exist.
# 
#     Will also ask the image to complain about any missing environment variables.
#     """
# 
#     fields = {
#         ("action", "run"): "The action to run with this image",
#         ("options", None): "The options to merge with the image options",
#         ("overrides", None): "The options to merge with the root configuration",
#         ("description", ""): "The description of the task",
#         ("label", "Project"): "The namespace when listing tasks",
#     }
# 
#     def setup(self, *args, **kwargs):
#         super(Task, self).setup(*args, **kwargs)
#         self.set_description()
# 
#     def set_description(self, available_actions=None):
#         if not self.description:
#             if not available_actions:
#                 from harpoon.actions import available_actions
#             if self.action in available_actions:
#                 self.description = available_actions[self.action].__doc__
# 
#     def run(self, collector, image, available_actions, tasks, **extras):
#         """Run this task"""
#         task_func = available_actions[self.action]
#         configuration = collector.configuration.wrapped()
# 
#         if self.options:
#             if image:
#                 configuration.update({"images": {image: self.options}})
#             else:
#                 configuration.update(self.options)
# 
#         # args like --port and the like should override what's in the options
#         # But themselves be overridden by the overrides
#         configuration.update(configuration["args_dict"].as_dict(), source="<args_dict>")
# 
#         if self.overrides:
#             overrides = {}
#             for key, val in self.overrides.items():
#                 overrides[key] = val
#                 if isinstance(val, MergedOptions):
#                     overrides[key] = dict(val.items())
#             configuration.update(overrides)
# 
#         if task_func.needs_image:
#             self.find_image(image, configuration)
#             image = configuration["images"][image]
#             image.find_missing_env()
# 
#         from harpoon.collector import Collector
# 
#         new_collector = Collector()
#         new_collector.configuration = configuration
#         new_collector.configuration_file = collector.configuration_file
#         artifact = configuration["harpoon"].artifact
#         return task_func(new_collector, image=image, tasks=tasks, artifact=artifact, **extras)
# 
#     def find_image(self, image, configuration):
#         """Complain if we don't have an image"""
#         images = configuration["images"]
#         available = list(images.keys())
# 
#         if not image:
#             info = {}
#             if available:
#                 info["available"] = available
#             raise BadOption("Please use --image to specify an image", **info)
# 
#         if image not in images:
#             raise BadOption("No such image", wanted=image, available=available)
# 
# Path: harpoon/errors.py
# class BadTask(HarpoonError):
#     desc = "Bad task"


# Path: harpoon/task_finder.py
from harpoon.actions import available_actions, default_actions
from harpoon.option_spec.task_objs import Task
from harpoon.errors import BadTask

"""
Responsible for finding tasks in the configuration and executing them
"""



class TaskFinder(object):
    def __init__(self, collector):
        self.tasks = {}
        self.collector = collector

    def image_finder(self, task):
        return getattr(
            self.tasks[task], "image", self.collector.configuration["harpoon"].chosen_image
        )

    def task_runner(self, task, **kwargs):
        if task not in self.tasks:
            raise BadTask("Unknown task", task=task, available=sorted(list(self.tasks.keys())))
        return self.tasks[task].run(
            self.collector, self.image_finder(task), available_actions, self.tasks, **kwargs
        )

    def default_tasks(self):
        """Return default tasks"""

        return dict((name, Task(action=name, label="Harpoon")) for name in default_actions)