mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
plugin manager and task manager (in progress)
This commit is contained in:
parent
6951f0b238
commit
55c430ed40
3 changed files with 57 additions and 4 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,9 +1,37 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue