plugin and task manager

This commit is contained in:
İsmail Başaran 2016-03-02 15:45:36 +02:00
parent 55c430ed40
commit 8939ac4a36
4 changed files with 22 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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