mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2025-12-06 07:42:03 +01:00
simple Plugin System
This commit is contained in:
parent
0b80ff95a3
commit
466e017cfb
|
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import plugin
|
||||
|
||||
13
plugin_test/plugin_test.py
Normal file
13
plugin_test/plugin_test.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import time
|
||||
import pluginloader
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
print ("Alarm!")
|
||||
for i in pluginloader.getPlugins():
|
||||
print("Loading plugin " + i["name"])
|
||||
plugin = pluginloader.loadPlugin(i)
|
||||
plugin.run()
|
||||
22
plugin_test/pluginloader.py
Normal file
22
plugin_test/pluginloader.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import imp
|
||||
import os
|
||||
|
||||
PluginFolder = "./plugins"
|
||||
MainModule = "__init__"
|
||||
|
||||
def getPlugins():
|
||||
plugins = []
|
||||
possibleplugins = os.listdir(PluginFolder)
|
||||
for i in possibleplugins:
|
||||
location = os.path.join(PluginFolder, i)
|
||||
if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location):
|
||||
continue
|
||||
info = imp.find_module(MainModule, [location])
|
||||
plugins.append({"name": i, "info": info})
|
||||
return plugins
|
||||
|
||||
def loadPlugin(plugin):
|
||||
return imp.load_module(MainModule, *plugin["info"])
|
||||
2
plugin_test/plugins/http/__init__.py
Normal file
2
plugin_test/plugins/http/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def run():
|
||||
print("throw HTTP Plugin")
|
||||
2
plugin_test/plugins/mysql/__init__.py
Normal file
2
plugin_test/plugins/mysql/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def run():
|
||||
print("Throw MySql Plugin")
|
||||
2
plugin_test/plugins/template/__init__.py
Normal file
2
plugin_test/plugins/template/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def run():
|
||||
print("Throw template Plugin")
|
||||
Loading…
Reference in a new issue