mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 15:32:19 +03:00
plugin and task manager
This commit is contained in:
parent
55c430ed40
commit
8939ac4a36
4 changed files with 22 additions and 5 deletions
|
@ -14,6 +14,8 @@ class Scope(object):
|
||||||
self.configurationManager=None
|
self.configurationManager=None
|
||||||
self.messageManager=None
|
self.messageManager=None
|
||||||
self.logger=None
|
self.logger=None
|
||||||
|
self.pluginManager=None
|
||||||
|
self.taskManager=None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getInstance():
|
def getInstance():
|
||||||
|
@ -50,3 +52,15 @@ class Scope(object):
|
||||||
|
|
||||||
def setMessageManager(self,messageManager):
|
def setMessageManager(self,messageManager):
|
||||||
self.messageManager = messageManager
|
self.messageManager = messageManager
|
||||||
|
|
||||||
|
def getPluginManager(self):
|
||||||
|
return self.pluginManager
|
||||||
|
|
||||||
|
def setPluginManager(self,pluginManager):
|
||||||
|
self.pluginManager = pluginManager
|
||||||
|
|
||||||
|
def getTaskManager(self):
|
||||||
|
return self.TaskManager
|
||||||
|
|
||||||
|
def setTaskManager(self,taskManager):
|
||||||
|
self.taskManager = taskManager
|
||||||
|
|
|
@ -17,18 +17,19 @@ class PluginManager(object):
|
||||||
self.pluginQueueDict = dict()
|
self.pluginQueueDict = dict()
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.getLogger()
|
||||||
|
|
||||||
def loadPlugins():
|
def loadPlugins(self):
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||||
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):
|
||||||
self.logger.debug('It is not a plugin location - %s - ',location)
|
self.logger.debug('It is not a plugin location - - ')
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
self.loadSinglePlugin(pname)
|
self.loadSinglePlugin(pname)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO error log
|
# TODO error log
|
||||||
|
pass
|
||||||
|
|
||||||
def loadSinglePlugin(self,pluginName):
|
def loadSinglePlugin(self,pluginName):
|
||||||
# TODO check already loaded plugin
|
# TODO check already loaded plugin
|
||||||
|
@ -44,7 +45,7 @@ class PluginManager(object):
|
||||||
info = imp.find_module(commandId, [location])
|
info = imp.find_module(commandId, [location])
|
||||||
return imp.load_module(commandId, *info)
|
return imp.load_module(commandId, *info)
|
||||||
else:
|
else:
|
||||||
self.logger.warning('Command id - %s - not found',commandId)
|
self.logger.warning('Command id - - not found')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def processTask(self,task):
|
def processTask(self,task):
|
||||||
|
@ -54,6 +55,7 @@ class PluginManager(object):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO error log here
|
# TODO error log here
|
||||||
# TODO update task - status to not found command
|
# TODO update task - status to not found command
|
||||||
|
pass
|
||||||
|
|
||||||
def reloadPlugins(self):
|
def reloadPlugins(self):
|
||||||
# Not implemented yet
|
# Not implemented yet
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
# -*- 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>
|
||||||
|
|
||||||
import Queue
|
from queue import Queue
|
||||||
|
|
||||||
class PluginQueue(Queue.PriorityQueue):
|
class PluginQueue(Queue):
|
||||||
def __contains__(self, item):
|
def __contains__(self, item):
|
||||||
with self.mutex:
|
with self.mutex:
|
||||||
return item in self.queue
|
return item in self.queue
|
||||||
|
|
|
@ -19,6 +19,7 @@ class TaskManager(object):
|
||||||
self.pluginManager.processTask(task)
|
self.pluginManager.processTask(task)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO error log here
|
# TODO error log here
|
||||||
|
pass
|
||||||
|
|
||||||
def saveTask(self,task):
|
def saveTask(self,task):
|
||||||
# TODO not implemented yet
|
# TODO not implemented yet
|
||||||
|
|
Loading…
Reference in a new issue