From b81d9b079b7da175160ed51f68b710873fcb29c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Wed, 25 May 2016 17:11:37 +0300 Subject: [PATCH] abstract classes merged --- opt/ahenk/base/plugin/AbstractCommand.py | 34 --------------------- opt/ahenk/base/plugin/AbstractPlugin.py | 11 ------- opt/ahenk/base/plugin/Plugin.py | 30 ------------------ opt/ahenk/base/plugin/abstract_plugin.py | 39 ++++++++++++++++++++++++ opt/ahenk/base/system/system.py | 7 +++-- 5 files changed, 44 insertions(+), 77 deletions(-) delete mode 100644 opt/ahenk/base/plugin/AbstractCommand.py delete mode 100644 opt/ahenk/base/plugin/AbstractPlugin.py create mode 100644 opt/ahenk/base/plugin/abstract_plugin.py diff --git a/opt/ahenk/base/plugin/AbstractCommand.py b/opt/ahenk/base/plugin/AbstractCommand.py deleted file mode 100644 index 289fcbb..0000000 --- a/opt/ahenk/base/plugin/AbstractCommand.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -# Author: İsmail BAŞARAN -from base.Scope import Scope - - -class AbstractCommand(object): - """docstring for AbstractCommand""" - - def __init__(self): - super(AbstractCommand, self).__init__() - self.scope = Scope.getInstance() - - def handle_task(task): - # implement this metot from command - pass - - def logger(self): - try: - return self.scope.getLogger() - except Exception as e: - print('Logger did not found') - return None - - def configurationManager(self): - try: - return self.scope.getConfigurationManager() - except Exception as e: - print('ConfigurationManager did not found') - return None - - def addMessageResponseQueue(self): - # TODO implement response queue - pass diff --git a/opt/ahenk/base/plugin/AbstractPlugin.py b/opt/ahenk/base/plugin/AbstractPlugin.py deleted file mode 100644 index b38721c..0000000 --- a/opt/ahenk/base/plugin/AbstractPlugin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python3 -# -*- coding: utf-8 -*- -# Author: İsmail BAŞARAN - - -class AbstractPlugin(object): - """This is base class for plugins""" - - def __init__(self, arg): - super(AbstrackPlugin, self).__init__() - self.arg = arg diff --git a/opt/ahenk/base/plugin/Plugin.py b/opt/ahenk/base/plugin/Plugin.py index 53f5000..00e3142 100644 --- a/opt/ahenk/base/plugin/Plugin.py +++ b/opt/ahenk/base/plugin/Plugin.py @@ -13,17 +13,6 @@ class Context(object): def __init__(self): self.data = {} self.scope = Scope().getInstance() - self.logger = self.scope.getLogger() - self.config_manager = self.scope.getConfigurationManager() - - def debug(self, message): - self.logger.debug('[PLUGIN]' + message) - - def info(self, message): - self.logger.info('[PLUGIN]' + message) - - def error(self, message): - self.logger.error('[PLUGIN]' + message) def put(self, var_name, data): self.data[var_name] = data @@ -34,25 +23,6 @@ class Context(object): def empty_data(self): self.data = {} - def execute(self, command): - return subprocess.Popen(command, shell=True) - - def execute_script(self, script_path, parameters=None): - command = [] - if script_path is not None: - command.append(script_path) - else: - raise Exception('[Context] Script is required') - - if parameters is not None: - for p in parameters: - command.append(p) - - return subprocess.check_call(command) - - def get_path(self): - return self.config_manager.get('PLUGIN', 'pluginfolderpath') - def create_response(self, code=None, message=None, data=None, content_type=None): self.data['responseCode'] = code self.data['responseMessage'] = message diff --git a/opt/ahenk/base/plugin/abstract_plugin.py b/opt/ahenk/base/plugin/abstract_plugin.py new file mode 100644 index 0000000..500809a --- /dev/null +++ b/opt/ahenk/base/plugin/abstract_plugin.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN +# Author: Volkan Şahin + +from base.Scope import Scope +from base.util.util import Util +from base.model.enum.MessageCode import MessageCode + + +class AbstractPlugin(Util): + """This is base class for plugins""" + + def __init__(self): + super(Util, self).__init__() + self.scope = Scope.getInstance() + self.message_code = MessageCode + + def handle_task(profile_data, context): + Scope.getInstance().getLogger().error('[PluginPolicy] Handle function not found') + + @property + def logger(self): + try: + return self.scope.getLogger() + except Exception as e: + self.scope.getLogger().error('[PluginPolicy] A problem occurred while getting logger. Error Message: {}'.format(str(e))) + return None + + def configuration_manager(self): + try: + return self.scope.getConfigurationManager() + except Exception as e: + self.logger().error('[PluginPolicy] A problem occurred while getting configuration manager. Error Message: {}'.format(str(e))) + return None + + def plugin_path(self): + return self.configuration_manager().get('PLUGIN', 'pluginfolderpath') + diff --git a/opt/ahenk/base/system/system.py b/opt/ahenk/base/system/system.py index 6d931bc..432e306 100644 --- a/opt/ahenk/base/system/system.py +++ b/opt/ahenk/base/system/system.py @@ -6,8 +6,6 @@ import platform import psutil import cpuinfo import re -from uuid import getnode as get_mac - class System: class Process(object): @@ -101,6 +99,11 @@ class System: def user_details(): return psutil.users() + @staticmethod + def last_login_username(): + #TODO + pass + class Os(object): @staticmethod