<commit_before>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin

import logging

from flexget import plugin
from flexget.config_schema import one_or_more
from flexget.event import event

log = logging.getLogger('notify')

ENTRY_CONTAINERS = ['entries', 'accepted', 'rejected', 'failed', 'undecided']


class Notify(object):
    schema = {
        'type': 'object',
        'properties': {
            'to': {'type': 'array', 'items':
                {'allOf': [
                    {'$ref': '/schema/plugins?group=notifiers'},
                    {'maxProperties': 1,
                     'error_maxProperties': 'Plugin options within notify plugin must be indented '
                                            '2 more spaces than the first letter of the plugin name.',
                     'minProperties': 1}]}},
            'scope': {'type': 'string', 'enum': ['task', 'entries']},
            'what': one_or_more({'type': 'string', 'enum': ENTRY_CONTAINERS})
        },
        'required': ['to'],
        'additionalProperties': False
    }

    @staticmethod
    def prepare_config(config):
        config.setdefault('what', ['accepted'])
        if not isinstance(config['what'], list):
            config['what'] = [config['what']]
        config.setdefault('scope', 'entries')
        return config

    def send_notification(self, task, config):
        config = self.prepare_config(config)
        scope = config['scope']
        what = config['what']

        # Build a list of entry containers or just uses task, depending on the scope
        iterate_on = [getattr(task, container) for container in what]

        for item in config['to']:
            for plugin_name, plugin_config in item.items():
                notifier = plugin.get_plugin_by_name(plugin_name).instance

                kwargs = {'task': task,
                          'scope': scope,
                          'iterate_on': iterate_on,
                          'test': task.options.test,
                          'config': plugin_config}

                log.info('Sending a notification to %s', plugin_name)
                notifier.notify(**kwargs)

    def on_task_start(self, task, config):
        # Suppress warnings about missing output plugins
        task.suppress_warnings = ['output']

    def on_task_exit(self, task, config):
        self.send_notification(task, config)


@event('plugin.register')
def register_plugin():
    plugin.register(Notify, 'notify', api_ver=2)<commit_msg>Correctly set suppressed plugin phase warning<commit_after>from __future__ import unicode_literals, division, absolute_import
from builtins import *  # noqa pylint: disable=unused-import, redefined-builtin

import logging

from flexget import plugin
from flexget.config_schema import one_or_more
from flexget.event import event

log = logging.getLogger('notify')

ENTRY_CONTAINERS = ['entries', 'accepted', 'rejected', 'failed', 'undecided']


class Notify(object):
    schema = {
        'type': 'object',
        'properties': {
            'to': {'type': 'array', 'items':
                {'allOf': [
                    {'$ref': '/schema/plugins?group=notifiers'},
                    {'maxProperties': 1,
                     'error_maxProperties': 'Plugin options within notify plugin must be indented '
                                            '2 more spaces than the first letter of the plugin name.',
                     'minProperties': 1}]}},
            'scope': {'type': 'string', 'enum': ['task', 'entries']},
            'what': one_or_more({'type': 'string', 'enum': ENTRY_CONTAINERS})
        },
        'required': ['to'],
        'additionalProperties': False
    }

    @staticmethod
    def prepare_config(config):
        config.setdefault('what', ['accepted'])
        if not isinstance(config['what'], list):
            config['what'] = [config['what']]
        config.setdefault('scope', 'entries')
        return config

    def send_notification(self, task, config):
        config = self.prepare_config(config)
        scope = config['scope']
        what = config['what']

        # Build a list of entry containers or just uses task, depending on the scope
        iterate_on = [getattr(task, container) for container in what]

        for item in config['to']:
            for plugin_name, plugin_config in item.items():
                notifier = plugin.get_plugin_by_name(plugin_name).instance

                kwargs = {'task': task,
                          'scope': scope,
                          'iterate_on': iterate_on,
                          'test': task.options.test,
                          'config': plugin_config}

                log.info('Sending a notification to %s', plugin_name)
                notifier.notify(**kwargs)

    def on_task_start(self, task, config):
        # Suppress warnings about missing output plugins
        if 'output' not in task.suppress_warnings:
            task.suppress_warnings.append('output')

    def on_task_exit(self, task, config):
        self.send_notification(task, config)


@event('plugin.register')
def register_plugin():
    plugin.register(Notify, 'notify', api_ver=2)
{'fraction_non_alphanumeric': 0.12017493820117893, 'fraction_numerical': 0.0015212017493820118, 'mean_word_length': 2.277258566978193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '499897', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1360, 'n_words': 380}