<commit_before>from __future__ import unicode_literals, division, absolute_import
import os
import logging

from flexget import plugin
from flexget.event import event
from flexget.utils.template import render_from_task, get_template, RenderError

PLUGIN_NAME = 'make_html'

log = logging.getLogger(PLUGIN_NAME)


class OutputHtml:

    schema = {
        'type': 'object',
        'properties': {
            'template': {'type': 'string'},
            'file': {'type': 'string'}
        },
        'required': ['file'],
        'additionalProperties': False
    }

    def on_task_output(self, task, config):
        # Use the default template if none is specified
        if not config.get('template'):
            config['template'] = 'default.template'

        filename = os.path.expanduser(config['template'])
        output = os.path.expanduser(config['file'])
        # Output to config directory if absolute path has not been specified
        if not os.path.isabs(output):
            output = os.path.join(task.manager.config_base, output)

        # create the template
        try:
            template = render_from_task(get_template(filename, PLUGIN_NAME), task)
            log.verbose('Writing output html to %s' % output)
            with open(output, 'w') as f:
                f.write(template.encode('utf-8'))
        except RenderError as e:
            log.error('Error while rendering entry %s, Error: %s' % (task, e))

@event('plugin.register')
def register_plugin():
    plugin.register(OutputHtml, PLUGIN_NAME, api_ver=2)
<commit_msg>Raise PluginError and log RenderError on make_html<commit_after>from __future__ import unicode_literals, division, absolute_import
import os
import logging

from flexget import plugin
from flexget.event import event
from flexget.utils.template import render_from_task, get_template, RenderError

PLUGIN_NAME = 'make_html'

log = logging.getLogger(PLUGIN_NAME)


class OutputHtml:

    schema = {
        'type': 'object',
        'properties': {
            'template': {'type': 'string'},
            'file': {'type': 'string'}
        },
        'required': ['file'],
        'additionalProperties': False
    }

    def on_task_output(self, task, config):
        # Use the default template if none is specified
        if not config.get('template'):
            config['template'] = 'default.template'

        filename = os.path.expanduser(config['template'])
        output = os.path.expanduser(config['file'])
        # Output to config directory if absolute path has not been specified
        if not os.path.isabs(output):
            output = os.path.join(task.manager.config_base, output)

        # create the template
        try:
            template = render_from_task(get_template(filename, PLUGIN_NAME), task)
            log.verbose('Writing output html to %s' % output)
            with open(output, 'w') as f:
                f.write(template.encode('utf-8'))
        except RenderError as e:
            log.error('Error while rendering task %s, Error: %s' % (task, e))
            raise plugin.PluginError('There was an error rendering the specified template')

@event('plugin.register')
def register_plugin():
    plugin.register(OutputHtml, PLUGIN_NAME, api_ver=2)

{'fraction_non_alphanumeric': 0.11046153846153846, 'fraction_numerical': 0.0012307692307692308, 'mean_word_length': 2.8202115158636896, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1439786', 'n_tokens_mistral': 912, 'n_tokens_neox': 899, 'n_words': 257}