This commit is contained in:
Volkan Şahin 2016-04-20 18:06:53 +03:00
commit 9dfbbcf5fc
4 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,13 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
class SafeMode(object):
def __init__(self,username):
self.username = username
@property
def obj_name(self):
return "SAFE_MODE"

View file

@ -85,6 +85,11 @@ class Plugin(threading.Thread):
elif obj_name == "KILL_SIGNAL":
self.keep_run = False
self.logger.debug('[Plugin] Killing queue ! Plugin Name : ' + str(self.name))
elif obj_name == "SAFE_MODE":
username = item_obj.username
safe_mode_module = Scope.getInstance().getPluginManager().find_safe_mode_module(self.name)
safe_mode_module.handle_safe_mode(username,self.context)
self.context.empty_data()
else:
self.logger.warning("[Plugin] Not supported object type " + obj_name)
except Exception as e:

View file

@ -9,6 +9,7 @@ from base.Scope import Scope
from base.plugin.Plugin import Plugin
from base.plugin.PluginQueue import PluginQueue
from base.model.PluginKillSignal import PluginKillSignal
from base.model.safe_mode import SafeMode
class PluginManager(object):
@ -131,6 +132,22 @@ class PluginManager(object):
else:
return True
def process_safe_mode(self,username):
for plugin_name in self.pluginQueueDict:
try:
self.pluginQueueDict[plugin_name].put(SafeMode(username),1)
except Exception as e:
self.logger.error('Exception occured when switching safe mode ' + str(e))
def find_safe_mode_module(self,plugin_name):
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
if os.path.isdir(location) and "safe.py" in os.listdir(location):
info = imp.find_module("safe", [location])
return imp.load_module("safe", *info)
else:
self.logger.warning('[PluginManager] safe.py not found Plugin Name : ' + str(plugin_name))
return None
def reloadSinglePlugin(self, pluginName):
# Not implemented yet

View file

@ -0,0 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
def handle_safe_mode(username,context):
pass