From ff54ec11e4c26ca3293091c20439079698249b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Wed, 20 Apr 2016 16:30:29 +0300 Subject: [PATCH] safe mode --- opt/ahenk/base/model/safe_mode.py | 13 +++++++++++++ opt/ahenk/base/plugin/Plugin.py | 5 +++++ opt/ahenk/base/plugin/PluginManager.py | 17 +++++++++++++++++ opt/ahenk/plugins/plugin1/safe.py | 7 +++++++ 4 files changed, 42 insertions(+) create mode 100644 opt/ahenk/base/model/safe_mode.py create mode 100644 opt/ahenk/plugins/plugin1/safe.py diff --git a/opt/ahenk/base/model/safe_mode.py b/opt/ahenk/base/model/safe_mode.py new file mode 100644 index 0000000..2baa555 --- /dev/null +++ b/opt/ahenk/base/model/safe_mode.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: Volkan Şahin + + +class SafeMode(object): + + def __init__(self,username): + self.username = username + + @property + def obj_name(self): + return "SAFE_MODE" \ No newline at end of file diff --git a/opt/ahenk/base/plugin/Plugin.py b/opt/ahenk/base/plugin/Plugin.py index 776da93..89dcf79 100644 --- a/opt/ahenk/base/plugin/Plugin.py +++ b/opt/ahenk/base/plugin/Plugin.py @@ -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: diff --git a/opt/ahenk/base/plugin/PluginManager.py b/opt/ahenk/base/plugin/PluginManager.py index 91d16ba..344d35a 100644 --- a/opt/ahenk/base/plugin/PluginManager.py +++ b/opt/ahenk/base/plugin/PluginManager.py @@ -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 diff --git a/opt/ahenk/plugins/plugin1/safe.py b/opt/ahenk/plugins/plugin1/safe.py new file mode 100644 index 0000000..062a10c --- /dev/null +++ b/opt/ahenk/plugins/plugin1/safe.py @@ -0,0 +1,7 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + + +def handle_safe_mode(username,context): + pass \ No newline at end of file