Version 2.3.7

Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-09-11 23:59:04 +02:00
parent 75094fc9ab
commit 81681f58eb

View File

@ -1,7 +1,8 @@
import os
import glob
import threading
import importlib, importlib.util
import importlib
import importlib.util
import logging
from concurrent.futures import ThreadPoolExecutor
@ -13,6 +14,7 @@ locks = {}
THREAD_POOL_SIZE = 10
executor = ThreadPoolExecutor(max_workers=THREAD_POOL_SIZE)
class Plugin:
@classmethod
def __init_subclass__(cls, **kwargs):
@ -30,6 +32,7 @@ class Plugin:
if cb is not None and callable(cb):
locks["%s::%s" % (plugin_name, attr_name)] = threading.Lock()
def toggle_plugin(name, enable=True):
"""
Load or unload a plugin
@ -68,6 +71,7 @@ def toggle_plugin(name, enable=True):
return False
def on(event_name, *args, **kwargs):
for plugin_name in loaded.keys():
one(plugin_name, event_name, *args, **kwargs)
@ -81,6 +85,7 @@ def locked_cb(lock_name, cb, *args, **kwargs):
with locks[lock_name]:
cb(*args, *kwargs)
def one(plugin_name, event_name, *args, **kwargs):
global loaded
@ -97,6 +102,7 @@ def one(plugin_name, event_name, *args, **kwargs):
logging.error("error while running %s.%s : %s" % (plugin_name, cb_name, e))
logging.error(e, exc_info=True)
def load_from_file(filename):
logging.debug("loading %s" % filename)
plugin_name = os.path.basename(filename.replace(".py", ""))
@ -105,6 +111,7 @@ def load_from_file(filename):
spec.loader.exec_module(instance)
return plugin_name, instance
def load_from_path(path, enabled=()):
global loaded, database
logging.debug("loading plugins from %s - enabled: %s" % (path, enabled))
@ -120,6 +127,7 @@ def load_from_path(path, enabled=()):
return loaded
def load(config):
enabled = [name for name, options in config['main']['plugins'].items() if
'enabled' in options and options['enabled']]