Ahenk/opt/ahenk/base/plugin/Plugin.py

34 lines
1020 B
Python
Raw Normal View History

2016-02-29 10:48:00 +02:00
#!/usr/bin/python3
2016-02-18 16:38:30 +02:00
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
import threading
from base.Scope import Scope
2016-02-18 16:38:30 +02:00
class Plugin(threading.Thread):
2016-02-18 16:38:30 +02:00
"""docstring for Plugin"""
def __init__(self, name, InQueue):
2016-03-23 10:04:31 +02:00
threading.Thread.__init__(self)
2016-02-18 16:38:30 +02:00
self.name = name
self.InQueue = InQueue
2016-03-23 10:04:31 +02:00
scope = Scope.getInstance()
self.pluginManager = scope.getPluginManager()
self.logger = scope.getLogger()
2016-03-23 10:04:31 +02:00
def run(self):
while True:
2016-03-23 10:04:31 +02:00
try:
task = self.InQueue.get(block=True)
command = Scope.getInstance().getPluginManager().findCommand(self.getName(), task.command_cls_id)
2016-03-23 10:04:31 +02:00
command.handle_task(task)
# TODO add result to response queue
2016-03-23 10:04:31 +02:00
except Exception as e:
# TODO error log here
2016-03-23 10:04:31 +02:00
self.logger.error("Plugin running exception " + str(e))
2016-02-18 16:38:30 +02:00
def getName(self):
return self.name