mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 10:52:17 +03:00
minor bug fixing and code formatting
This commit is contained in:
parent
4b580f26cb
commit
d6f48fd511
2 changed files with 38 additions and 17 deletions
|
@ -50,7 +50,9 @@ class PluginManager(object):
|
||||||
try:
|
try:
|
||||||
self.load_single_plugin(plugin_name)
|
self.load_single_plugin(plugin_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] Exception occurred while loading plugin ! Plugin name : {}. Error Message: {}'.format(str(plugin_name), str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] Exception occurred while loading plugin ! Plugin name : {}. Error Message: {}'.format(
|
||||||
|
str(plugin_name), str(e)))
|
||||||
self.logger.info('[PluginManager] Loaded plugins successfully.')
|
self.logger.info('[PluginManager] Loaded plugins successfully.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning('[PluginManager] Plugin folder path not found. Error Message: {}'.format(str(e)))
|
self.logger.warning('[PluginManager] Plugin folder path not found. Error Message: {}'.format(str(e)))
|
||||||
|
@ -58,11 +60,14 @@ class PluginManager(object):
|
||||||
def load_single_plugin(self, plugin_name):
|
def load_single_plugin(self, plugin_name):
|
||||||
# TODO check already loaded plugin
|
# TODO check already loaded plugin
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
||||||
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(location):
|
if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(
|
||||||
self.logger.debug('[PluginManager] It is not a plugin location ! There is no main module - {}'.format(str(location)))
|
location):
|
||||||
|
self.logger.debug(
|
||||||
|
'[PluginManager] It is not a plugin location ! There is no main module - {}'.format(str(location)))
|
||||||
else:
|
else:
|
||||||
if self.is_plugin_loaded(plugin_name):
|
if self.is_plugin_loaded(plugin_name):
|
||||||
self.logger.debug('[PluginManager] {0} plugin was already loaded. Reloading {0} plugin'.format(plugin_name))
|
self.logger.debug(
|
||||||
|
'[PluginManager] {0} plugin was already loaded. Reloading {0} plugin'.format(plugin_name))
|
||||||
# self.reload_single_plugin(plugin_name)
|
# self.reload_single_plugin(plugin_name)
|
||||||
else:
|
else:
|
||||||
self.pluginQueueDict[plugin_name] = PluginQueue()
|
self.pluginQueueDict[plugin_name] = PluginQueue()
|
||||||
|
@ -104,7 +109,9 @@ class PluginManager(object):
|
||||||
self.logger.debug('[PluginManager] {} plugin is loading (in reloading action)'.format(plugin_name))
|
self.logger.debug('[PluginManager] {} plugin is loading (in reloading action)'.format(plugin_name))
|
||||||
self.load_single_plugin(plugin_name)
|
self.load_single_plugin(plugin_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] A problem occurred while reloading {0} plugin. Error Message: {1}'.format(plugin_name, str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] A problem occurred while reloading {0} plugin. Error Message: {1}'.format(plugin_name,
|
||||||
|
str(e)))
|
||||||
|
|
||||||
def remove_plugins(self):
|
def remove_plugins(self):
|
||||||
try:
|
try:
|
||||||
|
@ -115,7 +122,8 @@ class PluginManager(object):
|
||||||
self.pluginQueueDict = dict()
|
self.pluginQueueDict = dict()
|
||||||
self.logger.debug('[PluginManager] All plugins were removed successfully.')
|
self.logger.debug('[PluginManager] All plugins were removed successfully.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] A problem occurred while removing plugins. Error Message :{0}.'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] A problem occurred while removing plugins. Error Message :{0}.'.format(str(e)))
|
||||||
|
|
||||||
def remove_single_plugin(self, plugin_name):
|
def remove_single_plugin(self, plugin_name):
|
||||||
try:
|
try:
|
||||||
|
@ -132,7 +140,9 @@ class PluginManager(object):
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] {} plugin not found.'.format(plugin_name))
|
self.logger.warning('[PluginManager] {} plugin not found.'.format(plugin_name))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name, str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] A problem occurred while removing {0} plugin. Error Message :{1}.'.format(plugin_name,
|
||||||
|
str(e)))
|
||||||
|
|
||||||
def find_command(self, pluginName, commandId):
|
def find_command(self, pluginName, commandId):
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName)
|
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName)
|
||||||
|
@ -156,12 +166,15 @@ class PluginManager(object):
|
||||||
if plugin_name in self.pluginQueueDict:
|
if plugin_name in self.pluginQueueDict:
|
||||||
self.pluginQueueDict[plugin_name].put(task, 1)
|
self.pluginQueueDict[plugin_name].put(task, 1)
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] {} plugin not found. Task was delayed. Ahenk will request plugin from Lider if distribution available'.format(plugin_name))
|
self.logger.warning(
|
||||||
|
'[PluginManager] {} plugin not found. Task was delayed. Ahenk will request plugin from Lider if distribution available'.format(
|
||||||
|
plugin_name))
|
||||||
self.delayed_tasks[plugin_name] = task
|
self.delayed_tasks[plugin_name] = task
|
||||||
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
||||||
self.messenger.send_direct_message(msg)
|
self.messenger.send_direct_message(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] Exception occurred while processing task. Error Message: {}'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] Exception occurred while processing task. Error Message: {}'.format(str(e)))
|
||||||
|
|
||||||
def find_policy_module(self, plugin_name):
|
def find_policy_module(self, plugin_name):
|
||||||
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), plugin_name)
|
||||||
|
@ -179,7 +192,7 @@ class PluginManager(object):
|
||||||
ahenk_profiles = policy.ahenk_profiles
|
ahenk_profiles = policy.ahenk_profiles
|
||||||
user_profiles = policy.user_profiles
|
user_profiles = policy.user_profiles
|
||||||
|
|
||||||
if ahenk_profiles is not None:
|
if ahenk_profiles is not None and len(ahenk_profiles) > 0:
|
||||||
self.logger.info('[PluginManager] Working on Ahenk profiles...')
|
self.logger.info('[PluginManager] Working on Ahenk profiles...')
|
||||||
for agent_profile in ahenk_profiles:
|
for agent_profile in ahenk_profiles:
|
||||||
same_plugin_profile = None
|
same_plugin_profile = None
|
||||||
|
@ -191,16 +204,20 @@ class PluginManager(object):
|
||||||
|
|
||||||
if same_plugin_profile is not None:
|
if same_plugin_profile is not None:
|
||||||
if agent_profile.overridable.lower() == 'true':
|
if agent_profile.overridable.lower() == 'true':
|
||||||
self.logger.debug('[PluginManager] Agent profile of {0} plugin will not executed because of profile override rules.'.format(agent_profile.plugin.name))
|
self.logger.debug(
|
||||||
|
'[PluginManager] Agent profile of {0} plugin will not executed because of '
|
||||||
|
'profile override rules.'.format(agent_profile.plugin.name))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] User profile of {0} plugin will not executed because of profile override rules.'.format(agent_profile.plugin.name))
|
self.logger.warning(
|
||||||
|
'[PluginManager] User profile of {0} plugin will not executed because of '
|
||||||
|
'profile override rules.'.format(agent_profile.plugin.name))
|
||||||
user_profiles.remove(same_plugin_profile)
|
user_profiles.remove(same_plugin_profile)
|
||||||
|
|
||||||
agent_profile.set_username(None)
|
agent_profile.set_username(None)
|
||||||
self.process_profile(agent_profile)
|
self.process_profile(agent_profile)
|
||||||
|
|
||||||
if user_profiles is not None:
|
if user_profiles is not None and len(user_profiles) > 0:
|
||||||
self.logger.info('[PluginManager] Working on User profiles...')
|
self.logger.info('[PluginManager] Working on User profiles...')
|
||||||
for user_profile in user_profiles:
|
for user_profile in user_profiles:
|
||||||
user_profile.set_username(username)
|
user_profile.set_username(username)
|
||||||
|
@ -215,12 +232,15 @@ class PluginManager(object):
|
||||||
if plugin_name in self.pluginQueueDict:
|
if plugin_name in self.pluginQueueDict:
|
||||||
self.pluginQueueDict[plugin_name].put(profile, 1)
|
self.pluginQueueDict[plugin_name].put(profile, 1)
|
||||||
else:
|
else:
|
||||||
self.logger.warning('[PluginManager] {} plugin not found. Profile was delayed. Ahenk will request plugin from Lider if distribution available'.format(plugin_name))
|
self.logger.warning(
|
||||||
|
'[PluginManager] {} plugin not found. Profile was delayed. Ahenk will request plugin from Lider if distribution available'.format(
|
||||||
|
plugin_name))
|
||||||
self.delayed_profiles[plugin_name] = profile
|
self.delayed_profiles[plugin_name] = profile
|
||||||
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
msg = self.message_manager.missing_plugin_message(PluginBean(name=plugin_name, version=plugin_ver))
|
||||||
self.scope.getMessenger().send_direct_message(msg)
|
self.scope.getMessenger().send_direct_message(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] Exception occurred while processing profile. Error Message: {}'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] Exception occurred while processing profile. Error Message: {}'.format(str(e)))
|
||||||
|
|
||||||
def check_plugin_exists(self, plugin_name, version=None):
|
def check_plugin_exists(self, plugin_name, version=None):
|
||||||
|
|
||||||
|
@ -255,7 +275,9 @@ class PluginManager(object):
|
||||||
try:
|
try:
|
||||||
self.pluginQueueDict[plugin_name].put(mode, 1)
|
self.pluginQueueDict[plugin_name].put(mode, 1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[PluginManager] Exception occurred while switching safe mode. Error Message : {}'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[PluginManager] Exception occurred while switching safe mode. Error Message : {}'.format(
|
||||||
|
str(e)))
|
||||||
|
|
||||||
def find_module(self, mode, plugin_name):
|
def find_module(self, mode, plugin_name):
|
||||||
mode = mode.lower().replace('_mode', '')
|
mode = mode.lower().replace('_mode', '')
|
||||||
|
|
|
@ -25,7 +25,6 @@ class TaskManager(object):
|
||||||
self.logger.debug('[TaskManager] Adding task ... ')
|
self.logger.debug('[TaskManager] Adding task ... ')
|
||||||
self.pluginManager.process_task(task)
|
self.pluginManager.process_task(task)
|
||||||
else:
|
else:
|
||||||
print(str(task.get_cron_str()))
|
|
||||||
self.scheduler.save_and_add_job(task)
|
self.scheduler.save_and_add_job(task)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue