fix: Allow reloading modules without a restart
All checks were successful
Build Docker / Build Image (push) Successful in 53s
All checks were successful
Build Docker / Build Image (push) Successful in 53s
This commit is contained in:
parent
12884fe696
commit
ce8c773db3
21
plugin.py
21
plugin.py
@ -6,12 +6,19 @@ import hashlib
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def import_module(module_name):
|
||||||
|
if module_name in sys.modules:
|
||||||
|
return importlib.reload(sys.modules[module_name])
|
||||||
|
else:
|
||||||
|
return importlib.import_module(module_name)
|
||||||
|
|
||||||
|
|
||||||
def listPlugins(update=False):
|
def listPlugins(update=False):
|
||||||
plugins = []
|
plugins = []
|
||||||
for file in os.listdir("plugins"):
|
for file in os.listdir("plugins"):
|
||||||
if file.endswith(".py"):
|
if file.endswith(".py"):
|
||||||
if file != "main.py":
|
if file != "main.py":
|
||||||
plugin = importlib.import_module("plugins."+file[:-3])
|
plugin = import_module("plugins."+file[:-3])
|
||||||
if "info" not in dir(plugin):
|
if "info" not in dir(plugin):
|
||||||
continue
|
continue
|
||||||
details = plugin.info
|
details = plugin.info
|
||||||
@ -42,7 +49,7 @@ def listPlugins(update=False):
|
|||||||
for file in os.listdir(f"customPlugins/{importPath}"):
|
for file in os.listdir(f"customPlugins/{importPath}"):
|
||||||
if file.endswith(".py"):
|
if file.endswith(".py"):
|
||||||
if file != "main.py":
|
if file != "main.py":
|
||||||
plugin = importlib.import_module(f"customPlugins.{importPath}."+file[:-3])
|
plugin = import_module(f"customPlugins.{importPath}."+file[:-3])
|
||||||
if "info" not in dir(plugin):
|
if "info" not in dir(plugin):
|
||||||
continue
|
continue
|
||||||
details = plugin.info
|
details = plugin.info
|
||||||
@ -106,7 +113,7 @@ def hashPlugin(plugin: str):
|
|||||||
|
|
||||||
|
|
||||||
def getPluginData(pluginStr: str):
|
def getPluginData(pluginStr: str):
|
||||||
plugin = importlib.import_module(pluginStr.replace("/","."))
|
plugin = import_module(pluginStr.replace("/","."))
|
||||||
|
|
||||||
# Check if the plugin is verified
|
# Check if the plugin is verified
|
||||||
signatures = []
|
signatures = []
|
||||||
@ -141,12 +148,12 @@ def getPluginData(pluginStr: str):
|
|||||||
|
|
||||||
|
|
||||||
def getPluginFunctions(plugin: str):
|
def getPluginFunctions(plugin: str):
|
||||||
plugin = importlib.import_module(plugin.replace("/","."))
|
plugin = import_module(plugin.replace("/","."))
|
||||||
return plugin.functions
|
return plugin.functions
|
||||||
|
|
||||||
|
|
||||||
def runPluginFunction(plugin: str, function: str, params: dict, authentication: str):
|
def runPluginFunction(plugin: str, function: str, params: dict, authentication: str):
|
||||||
plugin_module = importlib.import_module(plugin.replace("/","."))
|
plugin_module = import_module(plugin.replace("/","."))
|
||||||
if function not in plugin_module.functions:
|
if function not in plugin_module.functions:
|
||||||
return {"error": "Function not found"}
|
return {"error": "Function not found"}
|
||||||
|
|
||||||
@ -182,12 +189,12 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication:
|
|||||||
|
|
||||||
|
|
||||||
def getPluginFunctionInputs(plugin: str, function: str):
|
def getPluginFunctionInputs(plugin: str, function: str):
|
||||||
plugin = importlib.import_module(plugin.replace("/","."))
|
plugin = import_module(plugin.replace("/","."))
|
||||||
return plugin.functions[function]["params"]
|
return plugin.functions[function]["params"]
|
||||||
|
|
||||||
|
|
||||||
def getPluginFunctionReturns(plugin: str, function: str):
|
def getPluginFunctionReturns(plugin: str, function: str):
|
||||||
plugin = importlib.import_module(plugin.replace("/","."))
|
plugin = import_module(plugin.replace("/","."))
|
||||||
return plugin.functions[function]["returns"]
|
return plugin.functions[function]["returns"]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user