From 0a12fe6102da33977548ba0c277bd4fe34e262ab Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Thu, 16 Jun 2022 18:33:43 +0200 Subject: First draft of backend independent plugins --- backend/plugin_wrapper.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 backend/plugin_wrapper.py (limited to 'backend/plugin_wrapper.py') diff --git a/backend/plugin_wrapper.py b/backend/plugin_wrapper.py new file mode 100644 index 00000000..d41454df --- /dev/null +++ b/backend/plugin_wrapper.py @@ -0,0 +1,34 @@ +import multiprocessing +from json import load +from logging import getLogger +from os import path + +from plugin.plugin import get_plugin_backend + + +class PluginWrapper: + def __init__(self, plugin_relative_directory, plugin_path) -> None: + self.plugin_directory = path.join(plugin_path, plugin_relative_directory) + + json = load(open(path.join(self.plugin_directory, "plugin.json"), "r")) + + self.legacy = False + self.main_view_html = json["main_view_html"] if "main_view_html" in json else "" + self.tile_view_html = json["tile_view_html"] if "tile_view_html" in json else "" + self.legacy = self.main_view_html or self.tile_view_html + + self.name = json["name"] + self.author = json["author"] + self.flags = json["flags"] + self.logger = getLogger(f"{self.name}") + + self.backend = get_plugin_backend(json.get("backend"), self.plugin_directory, self.flags, self.logger) + + def call_method(self, method_name, args): + return self.backend.call_method(method_name, args) + + def start(self): + return self.backend.start() + + def __str__(self) -> str: + return self.name -- cgit v1.2.3