mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 10:52:17 +03:00
new modes added: init, login, logout, shutdown
This commit is contained in:
parent
3d685cd75e
commit
39ee7bb0bf
2 changed files with 53 additions and 20 deletions
|
@ -24,6 +24,9 @@ class Context(object):
|
||||||
def get(self, var_name):
|
def get(self, var_name):
|
||||||
return self.data[var_name]
|
return self.data[var_name]
|
||||||
|
|
||||||
|
def get_username(self):
|
||||||
|
return self.data['username']
|
||||||
|
|
||||||
def empty_data(self):
|
def empty_data(self):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
|
@ -151,17 +154,26 @@ class Plugin(threading.Thread):
|
||||||
elif obj_name == "KILL_SIGNAL":
|
elif obj_name == "KILL_SIGNAL":
|
||||||
self.keep_run = False
|
self.keep_run = False
|
||||||
self.logger.debug('[Plugin] Killing queue ! Plugin Name: {}'.format(str(self.name)))
|
self.logger.debug('[Plugin] Killing queue ! Plugin Name: {}'.format(str(self.name)))
|
||||||
elif obj_name == "SAFE_MODE":
|
elif 'MODE' in obj_name:
|
||||||
username = item_obj.username
|
module = Scope.getInstance().getPluginManager().find_module(obj_name, self.name)
|
||||||
safe_mode_module = Scope.getInstance().getPluginManager().find_safe_mode_module(self.name)
|
if module is not None:
|
||||||
safe_mode_module.handle_safe_mode(username, self.context)
|
if item_obj.obj_name in ('LOGIN_MODE', 'LOGOUT_MODE', 'SAFE_MODE'):
|
||||||
|
self.context.put('username', item_obj.username)
|
||||||
|
try:
|
||||||
|
self.logger.debug('[Plugin] {0} is running on {1} plugin'.format(str(item_obj.obj_name), str(self.name)))
|
||||||
|
module.handle_mode(self.context)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error('[Plugin] A problem occurred while running {0} on {1} plugin. Error Message: {2}'.format(str(obj_name), str(self.name), str(e)))
|
||||||
|
|
||||||
|
if item_obj.obj_name is 'SHUTDOWN_MODE':
|
||||||
|
self.logger.debug('[Plugin] {0} plugin is stopping...'.format(str(self.name)))
|
||||||
|
self.keep_run = False
|
||||||
else:
|
else:
|
||||||
self.logger.warning("[Plugin] Not supported object type: {}".format(str(obj_name)))
|
self.logger.warning("[Plugin] Not supported object type: {}".format(str(obj_name)))
|
||||||
|
|
||||||
# Empty context for next use
|
|
||||||
self.context.empty_data()
|
self.context.empty_data()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("[Plugin] Plugin running exception. Exception Message: {} ".format(str(e)))
|
self.logger.error("[Plugin] Plugin running exception about {0}. Exception Message: {1} ".format(obj_name, str(e)))
|
||||||
|
|
||||||
def get_execution_id(self, profile_id):
|
def get_execution_id(self, profile_id):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -6,11 +6,15 @@ import imp
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
|
from base.model.PluginBean import PluginBean
|
||||||
|
from base.model.PluginKillSignal import PluginKillSignal
|
||||||
|
from base.model.modes.init_mode import InitMode
|
||||||
|
from base.model.modes.login_mode import LoginMode
|
||||||
|
from base.model.modes.logout_mode import LogoutMode
|
||||||
|
from base.model.modes.safe_mode import SafeMode
|
||||||
|
from base.model.modes.shutdown_mode import ShutdownMode
|
||||||
from base.plugin.Plugin import Plugin
|
from base.plugin.Plugin import Plugin
|
||||||
from base.plugin.PluginQueue import PluginQueue
|
from base.plugin.PluginQueue import PluginQueue
|
||||||
from base.model.PluginKillSignal import PluginKillSignal
|
|
||||||
from base.model.PluginBean import PluginBean
|
|
||||||
from base.model.safe_mode import SafeMode
|
|
||||||
|
|
||||||
|
|
||||||
# TODO create base abstract class
|
# TODO create base abstract class
|
||||||
|
@ -173,22 +177,39 @@ class PluginManager(object):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def find_safe_mode_module(self, plugin_name):
|
def process_mode(self, mode_type, username=None):
|
||||||
|
mode = None
|
||||||
|
if mode_type == 'init':
|
||||||
|
mode = InitMode()
|
||||||
|
elif mode_type == 'shutdown':
|
||||||
|
mode = ShutdownMode()
|
||||||
|
elif mode_type == 'login':
|
||||||
|
mode = LoginMode(username)
|
||||||
|
elif mode_type == 'logout':
|
||||||
|
mode = LogoutMode(username)
|
||||||
|
elif mode_type == 'safe':
|
||||||
|
mode = SafeMode(username)
|
||||||
|
else:
|
||||||
|
self.logger.error('[PluginManager] Unknown mode type: {}'.format(mode_type))
|
||||||
|
|
||||||
|
if mode is not None:
|
||||||
|
for plugin_name in self.pluginQueueDict:
|
||||||
|
try:
|
||||||
|
self.pluginQueueDict[plugin_name].put(mode, 1)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error('[PluginManager] Exception occurred while switching safe mode. Error Message : {}'.format(str(e)))
|
||||||
|
|
||||||
|
def find_module(self, mode, plugin_name):
|
||||||
|
mode = mode.lower().replace('_mode', '')
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), 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])
|
if os.path.isdir(location) and (mode + ".py") in os.listdir(location):
|
||||||
return imp.load_module("safe", *info)
|
info = imp.find_module(mode, [location])
|
||||||
|
return imp.load_module(mode, *info)
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] safe.py not found Plugin Name : ' + str(plugin_name))
|
self.logger.warning('[PluginManager] safe.py not found Plugin Name : ' + str(plugin_name))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
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 reloadSinglePlugin(self, pluginName):
|
def reloadSinglePlugin(self, pluginName):
|
||||||
# Not implemented yet
|
# Not implemented yet
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue