simple Plugin System

This commit is contained in:
Schrolli 2015-05-18 09:04:16 +02:00
parent 0b80ff95a3
commit 466e017cfb
12 changed files with 41 additions and 5 deletions

View file

View file

View file

@ -1,5 +0,0 @@
#!/usr/bin/python
# -*- coding: cp1252 -*-
import plugin

View 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()

View 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"])

View file

@ -0,0 +1,2 @@
def run():
print("throw HTTP Plugin")

View file

@ -0,0 +1,2 @@
def run():
print("Throw MySql Plugin")

View file

@ -0,0 +1,2 @@
def run():
print("Throw template Plugin")