# Path: dotbot/plugin.py
# class Plugin(object):
#     """
#     Abstract base class for commands that process directives.
#     """
# 
#     def __init__(self, context):
#         self._context = context
#         self._log = Messenger()
# 
#     def can_handle(self, directive):
#         """
#         Returns true if the Plugin can handle the directive.
#         """
#         raise NotImplementedError
# 
#     def handle(self, directive, data):
#         """
#         Executes the directive.
# 
#         Returns true if the Plugin successfully handled the directive.
#         """
#         raise NotImplementedError
# 
# Path: dotbot/context.py
# class Context(object):
#     """
#     Contextual data and information for plugins.
#     """
# 
#     def __init__(self, base_directory, options=Namespace()):
#         self._base_directory = base_directory
#         self._defaults = {}
#         self._options = options
#         pass
# 
#     def set_base_directory(self, base_directory):
#         self._base_directory = base_directory
# 
#     def base_directory(self, canonical_path=True):
#         base_directory = self._base_directory
#         if canonical_path:
#             base_directory = os.path.realpath(base_directory)
#         return base_directory
# 
#     def set_defaults(self, defaults):
#         self._defaults = defaults
# 
#     def defaults(self):
#         return copy.deepcopy(self._defaults)
# 
#     def options(self):
#         return copy.deepcopy(self._options)


import os
from argparse import Namespace
from .plugin import Plugin
from .messenger import Messenger
from .context import Context
                    self._context.set_defaults(task[action])  # replace, not update
                    handled = True
                    # keep going, let other plugins handle this if they want
                for plugin in self._plugins:
                    if plugin.can_handle(action):
                        try:
                            local_success = plugin.handle(action, task[action])
                            if not local_success and self._exit:
                                # The action has failed exit
                                self._log.error("Action %s failed" % action)
                                return False
                            success &= local_success
                            handled = True
                        except Exception as err:
                            self._log.error(
                                "An error was encountered while executing action %s" % action
                            )
                            self._log.debug(err)
                            if self._exit:
                                # There was an execption exit
                                return False
                if not handled:
                    success = False
                    self._log.error("Action %s not handled" % action)
                    if self._exit:
                        # Invalid action exit
                        return False
        return success

    def _load_plugins(self):

# Path: dotbot/plugin.py
# class Plugin(object):
#     """
#     Abstract base class for commands that process directives.
#     """
# 
#     def __init__(self, context):
#         self._context = context
#         self._log = Messenger()
# 
#     def can_handle(self, directive):
#         """
#         Returns true if the Plugin can handle the directive.
#         """
#         raise NotImplementedError
# 
#     def handle(self, directive, data):
#         """
#         Executes the directive.
# 
#         Returns true if the Plugin successfully handled the directive.
#         """
#         raise NotImplementedError
# 
# Path: dotbot/context.py
# class Context(object):
#     """
#     Contextual data and information for plugins.
#     """
# 
#     def __init__(self, base_directory, options=Namespace()):
#         self._base_directory = base_directory
#         self._defaults = {}
#         self._options = options
#         pass
# 
#     def set_base_directory(self, base_directory):
#         self._base_directory = base_directory
# 
#     def base_directory(self, canonical_path=True):
#         base_directory = self._base_directory
#         if canonical_path:
#             base_directory = os.path.realpath(base_directory)
#         return base_directory
# 
#     def set_defaults(self, defaults):
#         self._defaults = defaults
# 
#     def defaults(self):
#         return copy.deepcopy(self._defaults)
# 
#     def options(self):
#         return copy.deepcopy(self._options)


# Path: dotbot/dispatcher.py
import os
from argparse import Namespace
from .plugin import Plugin
from .messenger import Messenger
from .context import Context

                    self._context.set_defaults(task[action])  # replace, not update
                    handled = True
                    # keep going, let other plugins handle this if they want
                for plugin in self._plugins:
                    if plugin.can_handle(action):
                        try:
                            local_success = plugin.handle(action, task[action])
                            if not local_success and self._exit:
                                # The action has failed exit
                                self._log.error("Action %s failed" % action)
                                return False
                            success &= local_success
                            handled = True
                        except Exception as err:
                            self._log.error(
                                "An error was encountered while executing action %s" % action
                            )
                            self._log.debug(err)
                            if self._exit:
                                # There was an execption exit
                                return False
                if not handled:
                    success = False
                    self._log.error("Action %s not handled" % action)
                    if self._exit:
                        # Invalid action exit
                        return False
        return success

    def _load_plugins(self):

        self._plugins = [plugin(self._context) for plugin in Plugin.__subclasses__()]