<commit_before># -*- coding: utf-8 -*-

# Copyright 2011-2013 Universidad Politécnica de Madrid

# This file is part of Wirecluod.

# Wirecloud is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Wirecloud is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Wirecloud.  If not, see <http://www.gnu.org/licenses/>.

import inspect

from django.utils.importlib import import_module
from django.conf.urls.defaults import patterns
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import get_ns_resolver, get_resolver, get_script_prefix, NoReverseMatch
from django.utils.encoding import force_unicode
from django.utils.regex_helper import normalize

_wirecloud_plugins = None
_wirecloud_features = None

def find_wirecloud_plugins():

    from django.conf import settings

    modules = []

    for app in settings.INSTALLED_APPS:

        if app == 'wirecloud.platform':
            continue

        try:
            mod = import_module('%s.plugins' % app)
        except:
            continue

        mod_plugins = [cls for name, cls in mod.__dict__.items() if inspect.isclass(cls) and cls != WirecloudPlugin and issubclass(cls, WirecloudPlugin)]
        modules += mod_plugins

    return modules

def get_plugins():
    from django.conf import settings
    global _wirecloud_plugins
    global _wirecloud_features

    if _wirecloud_plugins is None:
        modules = getattr(settings, 'WIRECLOUD_PLUGINS', None)
        if modules is None:
            modules = find_wirecloud_plugins()

        plugins = []
        features = {}

        def add_plugin(module, plugin):

            plugin_features = plugin.get_features()
            for feature_name in plugin_features:
                if feature_name in features:
                    raise ImproperlyConfigured('Feature already declared by wirecloud plugin %s' % features[feature_name]['module'])

                features[feature_name] = {
                    'module': module,
                    'version': plugin_features[feature_name],
                }

            plugins.append(plugin)

        from wirecloud.platform.core.plugins import WirecloudCorePlugin
        add_plugin('wirecloud.platform.WirecloudCorePlugin', WirecloudCorePlugin())

        for entry in modules:
            if isinstance(entry, basestring):
                i = path.rfind('.')
                module, attr = path[:i], path[i + 1:]
                try:
                    mod = import_module(module)
                except ImportError, e:
                    raise ImproperlyConfigured('Error importing wirecloud plugin module %s: "%s"' % (module, e))

                try:
                    plugin = getattr(mod, attr)()
                except AttributeError:<commit_msg>Fix some problems handling plugins<commit_after># -*- coding: utf-8 -*-

# Copyright 2011-2013 Universidad Politécnica de Madrid

# This file is part of Wirecluod.

# Wirecloud is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Wirecloud is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Wirecloud.  If not, see <http://www.gnu.org/licenses/>.

import inspect

from django.utils.importlib import import_module
from django.conf.urls.defaults import patterns
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import get_ns_resolver, get_resolver, get_script_prefix, NoReverseMatch
from django.utils.encoding import force_unicode
from django.utils.regex_helper import normalize

_wirecloud_plugins = None
_wirecloud_features = None

def find_wirecloud_plugins():

    from django.conf import settings

    modules = []

    for app in settings.INSTALLED_APPS:

        if app == 'wirecloud.platform':
            continue

        try:
            mod = import_module('%s.plugins' % app)
        except:
            continue

        mod_plugins = [cls for name, cls in mod.__dict__.items() if inspect.isclass(cls) and cls != WirecloudPlugin and issubclass(cls, WirecloudPlugin)]
        modules += mod_plugins

    return modules

def get_plugins():
    from django.conf import settings
    global _wirecloud_plugins
    global _wirecloud_features

    if _wirecloud_plugins is None:
        modules = getattr(settings, 'WIRECLOUD_PLUGINS', None)
        if modules is None:
            modules = find_wirecloud_plugins()

        plugins = []
        features = {}

        def add_plugin(module, plugin):

            plugin_features = plugin.get_features()
            for feature_name in plugin_features:
                if feature_name in features:
                    raise ImproperlyConfigured('Feature already declared by wirecloud plugin %s' % features[feature_name]['module'])

                features[feature_name] = {
                    'module': module,
                    'version': plugin_features[feature_name],
                }

            plugins.append(plugin)

        from wirecloud.platform.core.plugins import WirecloudCorePlugin
        add_plugin('wirecloud.platform.WirecloudCorePlugin', WirecloudCorePlugin())

        for entry in modules:
            if isinstance(entry, basestring):
                i = entry.rfind('.')
                module, attr = entry[:i], entry[i + 1:]
                try:
                    mod = import_module(module)
                except ImportError, e:
                    raise ImproperlyConfigured('Error importing wirecloud plugin module %s: "%s"' % (module, e))

                try:
                    plugin = getattr(mod, attr)()
                except AttributeError:
{'fraction_non_alphanumeric': 0.07260828918666251, 'fraction_numerical': 0.003427859146151449, 'mean_word_length': 2.5840312674483528, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1191302', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1604, 'n_words': 563}