# 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


class Dispatcher(object):
    def __init__(
        self, base_directory, only=None, skip=None, exit_on_failure=False, options=Namespace()
    ):
        self._log = Messenger()
        self._setup_context(base_directory, options)
        self._load_plugins()
        self._only = only
        self._skip = skip
        self._exit = exit_on_failure

    def _setup_context(self, base_directory, options):
        path = os.path.abspath(os.path.expanduser(base_directory))
        if not os.path.exists(path):
            raise DispatchError("Nonexistent base directory")

# 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



class Dispatcher(object):
    def __init__(
        self, base_directory, only=None, skip=None, exit_on_failure=False, options=Namespace()
    ):
        self._log = Messenger()
        self._setup_context(base_directory, options)
        self._load_plugins()
        self._only = only
        self._skip = skip
        self._exit = exit_on_failure

    def _setup_context(self, base_directory, options):
        path = os.path.abspath(os.path.expanduser(base_directory))
        if not os.path.exists(path):
            raise DispatchError("Nonexistent base directory")

        self._context = Context(path, options)