mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 21:22:21 +03:00
plugin queue and load modules
This commit is contained in:
parent
83f4e86329
commit
3952cafc1a
2 changed files with 37 additions and 18 deletions
|
@ -2,15 +2,20 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||||
from base.plugin.Plugin import Plugin
|
from base.plugin.Plugin import Plugin
|
||||||
|
from base.plugin.PluginQueue import PluginQueue
|
||||||
|
from base.Scope import Scope
|
||||||
import imp,os
|
import imp,os
|
||||||
|
|
||||||
class PluginManager(object):
|
class PluginManager(object):
|
||||||
"""docstring for PluginManager"""
|
"""docstring for PluginManager"""
|
||||||
#implement logger
|
#implement logger
|
||||||
def __init__(self, configManager):
|
def __init__(self):
|
||||||
super(PluginManager, self).__init__()
|
super(PluginManager, self).__init__()
|
||||||
self.configManager = configManager
|
scope = Scope.getInstance()
|
||||||
|
self.configManager = scope.getConfigurationManager()
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
|
self.pluginQueueDict = dict()
|
||||||
|
self.logger = scope.getLogger()
|
||||||
|
|
||||||
def loadPlugins():
|
def loadPlugins():
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
|
@ -18,22 +23,26 @@ class PluginManager(object):
|
||||||
for pname in possibleplugins:
|
for pname in possibleplugins:
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname)
|
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):
|
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(location):
|
||||||
|
#TODO debug log here
|
||||||
continue
|
continue
|
||||||
info = imp.find_module(self.configManager.get("PLUGIN", "mainModuleName"), [location])
|
try:
|
||||||
#mainModule = self.loadSinglePlugin(info):
|
self.loadSinglePlugin(pname)
|
||||||
self.plugins.append(Plugin(pname,mainModule))
|
except Exception as e:
|
||||||
|
# TODO error log
|
||||||
|
|
||||||
def createQueueForPlugin(self):
|
def loadSinglePlugin(self,pluginName):
|
||||||
|
# TODO check already loaded plugin
|
||||||
|
self.pluginQueueDict[pluginName]=PluginQueue()
|
||||||
|
plugin = Plugin(pluginName,self.pluginQueueDict[pluginName])
|
||||||
|
plugin.setDaemon(True)
|
||||||
|
plugin.start()
|
||||||
|
self.plugins.append(plugin)
|
||||||
|
|
||||||
|
def findCommand(self,pluginName,commandId):
|
||||||
def loadSinglePlugin(self,pluginInfo):
|
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname)
|
||||||
return imp.load_module(self.configManager.get("PLUGIN", "mainModuleName"), *pluginInfo)
|
if os.path.dir(location) and commandId + ".py" in os.listdir(location):
|
||||||
|
info = imp.find_module(commandId, [location])
|
||||||
def findSinglePlugin(self,pluginName):
|
return imp.load_module(commandId, *info)
|
||||||
for plugin in self.getPlugins():
|
else:
|
||||||
if plugin["name"] == self.plugins:
|
self.logger.warning('Command id - %s - not found',commandId)
|
||||||
return self.loadSinglePlugin(plugin)
|
return None
|
||||||
|
|
||||||
|
|
||||||
def findCommand(self,comamndName):
|
|
||||||
pass
|
|
||||||
|
|
10
opt/ahenk/base/plugin/PluginQueue.py
Normal file
10
opt/ahenk/base/plugin/PluginQueue.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||||
|
|
||||||
|
import Queue
|
||||||
|
|
||||||
|
class PluginQueue(Queue.PriorityQueue):
|
||||||
|
def __contains__(self, item):
|
||||||
|
with self.mutex:
|
||||||
|
return item in self.queue
|
Loading…
Reference in a new issue