1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-09-18 04:22:21 +00:00

Added plugins by default and monkey patching

Fixes #2
This commit is contained in:
J. Fernando Sánchez
2015-06-18 17:52:02 +02:00
parent 384aba4654
commit 7c2e0ddec7
12 changed files with 2765 additions and 19 deletions

View File

@@ -1,5 +1,9 @@
"""
"""
import gevent
from gevent import monkey
monkey.patch_all()
from .plugins import SenpyPlugin, SentimentPlugin, EmotionPlugin
from .models import Error
from .blueprints import nif_blueprint
@@ -23,15 +27,16 @@ class Senpy(object):
""" Default Senpy extension for Flask """
def __init__(self, app=None, plugin_folder="plugins"):
def __init__(self, app=None, plugin_folder="plugins", base_plugins=True):
self.app = app
base_folder = os.path.join(os.path.dirname(__file__), "plugins")
self._search_folders = set()
self._outdated = True
for folder in (base_folder, plugin_folder):
self.add_folder(folder)
self.add_folder(plugin_folder)
if base_plugins:
base_folder = os.path.join(os.path.dirname(__file__), "plugins")
self.add_folder(base_folder)
if app is not None:
self.init_app(app)
@@ -124,7 +129,13 @@ class Senpy(object):
def activate_plugin(self, plugin_name, sync=False):
plugin = self.plugins[plugin_name]
th = gevent.spawn(plugin.activate)
def act():
try:
plugin.activate()
except Exception as ex:
logger.error("Error activating plugin {}: {}".format(plugin.name,
ex))
th = gevent.spawn(act)
th.link_value(partial(self._set_active_plugin, plugin_name, True))
if sync:
th.join()