<commit_before>#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from sys                import exit

class ByteBotPluginLoader:
    PLUGINS = {} 

    def __init__(self, plugins, plugin_path='plugins'):
        """
        plugins:        tupel with plugins
        plugin_path:    path to plugins
                        MUST NOT end with a trailing slash
        """
        path = plugin_path.replace('/', '.')
        for plugin in plugins:
            try:
                self.PLUGINS[plugin] = getattr(
                    __import__("%s.%s" % (path, plugin)).__dict__[plugin],
                    plugin.title()
                )
            except Exception, e:
                print("FATAL: Could not import plugin %s" % plugin)
                print(e)
                #exit(255)

    def runCommands(self, fn, args={}):
        for plugin in self.PLUGINS:
            try:
                method = getattr(plugin, fn)
                method(**args)
            except Exception:
                print("WARNING: An error occured while executing %s in %s with %s" %
                     (fn, plugin, args))<commit_msg>Better error handling in plugin loader<commit_after>#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from sys                import exit

class ByteBotPluginLoader:
    PLUGINS = {} 

    def __init__(self, plugins, plugin_path='plugins'):
        """
        plugins:        tupel with plugins
        plugin_path:    path to plugins
                        MUST NOT end with a trailing slash
        """
        path = plugin_path.replace('/', '.')
        for plugin in plugins:
            try:
                self.PLUGINS[plugin] = getattr(
                    __import__("%s.%s" % (path, plugin)).__dict__[plugin],
                    plugin.title()
                )
            except Exception, e:
                print("FATAL: Could not import plugin %s.%s" %
                      (path, plugin))
                exit(255)

    def runCommands(self, fn, args={}):
        for plugin in self.PLUGINS:
            try:
                method = getattr(plugin, fn)
                method(**args)
            except Exception:
                print("WARNING: An error occured while executing %s in %s with %s" %
                     (fn, plugin, args))
{'fraction_non_alphanumeric': 0.10673665791776028, 'fraction_numerical': 0.004374453193350831, 'mean_word_length': 1.3847758081334725, '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': '7183141', 'n_tokens_mistral': 632, 'n_tokens_neox': 587, 'n_words': 172}