# Path: pipelines/plugins/base_executor.py
# class BaseExecutorPlugin(BasePlugin):
#     dry_run = False
# 
#     def call(self, *args, **kwargs):
#         result = self.execute(*args, **kwargs)
#         if not isinstance(result, TaskResult):
#             raise PipelineError('Executor did not return type ExecutionResult, got {}'.format(type(result)))
# 
#         return result
# 
#     def execute(self, command):
#         print 'Running executor with command: %s' % command
# 
# Path: pipelines/pipeline/task.py
# class TaskResult(dict):
#     def __init__(self, status, message='', data={}, return_obj={}):
#         self['status'] = status
#         self['message'] = message
#         self['data'] = data
#         self['return_obj'] = return_obj
# 
#     @property
#     def status(self):
#         return self.get('status')
# 
#     @property
#     def message(self):
#         return self.get('message')
# 
#     @property
#     def data(self):
#         return self.get('data')
# 
#     @property
#     def return_obj(self):
#         return self.get('return_obj')
# 
#     def is_successful(self):
#         return self.status == EXECUTION_SUCCESSFUL
# 
# EXECUTION_SUCCESSFUL = 0
# 
# EXECUTION_FAILED = 1
# 
# Path: pipelines/plugin/exceptions.py
# class PluginError(RuntimeError):
#     pass


import logging
import requests
from pipelines.plugins.base_executor import BaseExecutorPlugin
from pipelines.pipeline.task import TaskResult, EXECUTION_SUCCESSFUL, EXECUTION_FAILED
from pipelines.plugin.exceptions import PluginError

log = logging.getLogger('pipelines')

RETRY_COUNT = 2

class SlackExecutor(BaseExecutorPlugin):
    hook_prefix = 'slack'
    hooks = ('execute',)

    # webhook_url = 'https://hooks.slack.com/services/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'

    def __init__(self, slack_webhook):
        self.slack_webhook = slack_webhook

    def execute(self, args_dict):
        if not self.slack_webhook:
            raise PluginError('SlackExecutor is missing slack_webhook parameter. Can not execute')

        if 'message' not in args_dict:
            raise PluginError('SlackExecutor got incorrect arguments, got: {}'.format(
                args_dict.keys()
            ))
        message = args_dict['message']

        if self.dry_run:

# Path: pipelines/plugins/base_executor.py
# class BaseExecutorPlugin(BasePlugin):
#     dry_run = False
# 
#     def call(self, *args, **kwargs):
#         result = self.execute(*args, **kwargs)
#         if not isinstance(result, TaskResult):
#             raise PipelineError('Executor did not return type ExecutionResult, got {}'.format(type(result)))
# 
#         return result
# 
#     def execute(self, command):
#         print 'Running executor with command: %s' % command
# 
# Path: pipelines/pipeline/task.py
# class TaskResult(dict):
#     def __init__(self, status, message='', data={}, return_obj={}):
#         self['status'] = status
#         self['message'] = message
#         self['data'] = data
#         self['return_obj'] = return_obj
# 
#     @property
#     def status(self):
#         return self.get('status')
# 
#     @property
#     def message(self):
#         return self.get('message')
# 
#     @property
#     def data(self):
#         return self.get('data')
# 
#     @property
#     def return_obj(self):
#         return self.get('return_obj')
# 
#     def is_successful(self):
#         return self.status == EXECUTION_SUCCESSFUL
# 
# EXECUTION_SUCCESSFUL = 0
# 
# EXECUTION_FAILED = 1
# 
# Path: pipelines/plugin/exceptions.py
# class PluginError(RuntimeError):
#     pass


# Path: pipelines/plugins/slack_executor.py
import logging
import requests
from pipelines.plugins.base_executor import BaseExecutorPlugin
from pipelines.pipeline.task import TaskResult, EXECUTION_SUCCESSFUL, EXECUTION_FAILED
from pipelines.plugin.exceptions import PluginError


log = logging.getLogger('pipelines')

RETRY_COUNT = 2

class SlackExecutor(BaseExecutorPlugin):
    hook_prefix = 'slack'
    hooks = ('execute',)

    # webhook_url = 'https://hooks.slack.com/services/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'

    def __init__(self, slack_webhook):
        self.slack_webhook = slack_webhook

    def execute(self, args_dict):
        if not self.slack_webhook:
            raise PluginError('SlackExecutor is missing slack_webhook parameter. Can not execute')

        if 'message' not in args_dict:
            raise PluginError('SlackExecutor got incorrect arguments, got: {}'.format(
                args_dict.keys()
            ))
        message = args_dict['message']

        if self.dry_run:

            return TaskResult(EXECUTION_SUCCESSFUL)