summaryrefslogtreecommitdiff
path: root/backend/plugin_wrapper.py
blob: b158f8610f6472585be1581e28c894b99621b10a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 stop(self):
        return self.backend.stop()

    def __str__(self) -> str:
        return self.name