From 55c430ed40b8f479c8acab27ed7655428c1eed1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Wed, 2 Mar 2016 11:59:19 +0200 Subject: [PATCH] plugin manager and task manager (in progress) --- opt/ahenk/base/plugin/Plugin.py | 3 ++- opt/ahenk/base/plugin/PluginManager.py | 28 ++++++++++++++++++++++-- opt/ahenk/base/task/TaskManager.py | 30 +++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/opt/ahenk/base/plugin/Plugin.py b/opt/ahenk/base/plugin/Plugin.py index 99387da..f942e8d 100644 --- a/opt/ahenk/base/plugin/Plugin.py +++ b/opt/ahenk/base/plugin/Plugin.py @@ -16,11 +16,12 @@ class Plugin(threading.Thread): def run(): try: task=self.InQueue.get() - command = self.pluginManager.findCommand(task.getCommandId()) + command = self.pluginManager.findCommand(self.getName(),task.getCommandId()) command.handle_task(task) # TODO add result to response queue except Exception as e: + #TODO error log here print("exception occured when executing plugin") def getName(self): diff --git a/opt/ahenk/base/plugin/PluginManager.py b/opt/ahenk/base/plugin/PluginManager.py index 2e35deb..caee36c 100644 --- a/opt/ahenk/base/plugin/PluginManager.py +++ b/opt/ahenk/base/plugin/PluginManager.py @@ -23,7 +23,7 @@ class PluginManager(object): 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): - #TODO debug log here + self.logger.debug('It is not a plugin location - %s - ',location) continue try: self.loadSinglePlugin(pname) @@ -39,10 +39,34 @@ class PluginManager(object): self.plugins.append(plugin) def findCommand(self,pluginName,commandId): - location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname) + location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName) if os.path.dir(location) and commandId + ".py" in os.listdir(location): info = imp.find_module(commandId, [location]) return imp.load_module(commandId, *info) else: self.logger.warning('Command id - %s - not found',commandId) return None + + def processTask(self,task): + try: + if task.getPluginId().lower() in self.pluginQueueDict : + self.pluginQueueDict[task.getPluginId().lower()].put(task,task.priority) + except Exception as e: + # TODO error log here + # TODO update task - status to not found command + + def reloadPlugins(self): + # Not implemented yet + pass + + def checkPluginExists(self,pluginName): + # Not implemented yet + pass + + def reloadSinglePlugin(self,pluginName): + # Not implemented yet + pass + + def checkCommandExist(self,pluginName,commandId): + # Not implemented yet + pass diff --git a/opt/ahenk/base/task/TaskManager.py b/opt/ahenk/base/task/TaskManager.py index e011f1b..874ce07 100644 --- a/opt/ahenk/base/task/TaskManager.py +++ b/opt/ahenk/base/task/TaskManager.py @@ -1,9 +1,37 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: İsmail BAŞARAN +from base.Scope import Scope class TaskManager(object): """docstring for TaskManager""" def __init__(self): super(TaskManager, self).__init__() - + scope = Scope.getInstance() + self.pluginManager = scope.getPluginManager() + self.logger= scope.getLogger() + + def addTask(self,task): + try: + # TODO add log + # TODO save task to database + # TODO send task received message + self.pluginManager.processTask(task) + except Exception as e: + # TODO error log here + + def saveTask(self,task): + # TODO not implemented yet + # task reveiced to ahenk save to db firstly. + # if user close before processing task you can load from db for process + pass + + def updateTask(self,task): + # TODO not implemented yet + # This is updates task status processing - processed ... + pass + + def deleteTask(self,task): + # TODO not implemented yet + # remove task if it is processed + pass