mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 16:52:25 +03:00
initial plugin manager
This commit is contained in:
parent
12ae1bc696
commit
cd904daac4
3 changed files with 49 additions and 27 deletions
|
@ -1,34 +1,10 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
import imp,os
|
||||
"""
|
||||
|
||||
|
||||
class AbstractPlugin(object):
|
||||
This is base class for plugins
|
||||
"""This is base class for plugins"""
|
||||
def __init__(self, arg):
|
||||
super(AbstrackPlugin, self).__init__()
|
||||
self.arg = arg
|
||||
"""
|
||||
pluginFolder = '/home/ismail/devzone/workspace/LiderAhenk/ahenk/opt/ahenk/plugins'
|
||||
mainModule = 'main'
|
||||
|
||||
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"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for i in getPlugins():
|
||||
print("Loading plugin " + i["name"])
|
||||
plugin = loadPlugin(i)
|
||||
plugin.run("tabisi")
|
||||
|
|
16
opt/ahenk/base/plugin/Plugin.py
Normal file
16
opt/ahenk/base/plugin/Plugin.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
class Plugin(object):
|
||||
"""docstring for Plugin"""
|
||||
def __init__(self, name,mainModule):
|
||||
super(Plugin, self).__init__()
|
||||
self.name = name
|
||||
self.mainModule = mainModule
|
||||
|
||||
def getName(self):
|
||||
return self.name
|
||||
|
||||
def getMainModule(self):
|
||||
return self.mainModule
|
30
opt/ahenk/base/plugin/PluginManager.py
Normal file
30
opt/ahenk/base/plugin/PluginManager.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
from base.plugin.Plugin import Plugin
|
||||
import imp,os
|
||||
|
||||
class PluginManager(object):
|
||||
"""docstring for PluginManager"""
|
||||
#implement logger
|
||||
def __init__(self, configManager):
|
||||
super(PluginManager, self).__init__()
|
||||
self.configManager = configManager
|
||||
self.plugins = []
|
||||
|
||||
def loadPlugins():
|
||||
self.plugins = []
|
||||
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||
for pname in possibleplugins:
|
||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname)
|
||||
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(location):
|
||||
continue
|
||||
info = imp.find_module(self.configManager.get("PLUGIN", "mainModuleName"), [location])
|
||||
mainModule = self.loadSinglePlugin(info):
|
||||
self.plugins.append(Plugin(pname,mainModule))
|
||||
|
||||
def loadSinglePlugin(pluginInfo):
|
||||
return imp.load_module(self.configManager.get("PLUGIN", "mainModuleName"), pluginInfo)
|
||||
|
||||
def findSinglePlugin(pluginName):
|
||||
pass # Not implemented yet
|
Loading…
Reference in a new issue