abstract classes merged

This commit is contained in:
Volkan Şahin 2016-05-25 17:11:37 +03:00
parent 63b28cefe5
commit b81d9b079b
5 changed files with 44 additions and 77 deletions

View file

@ -1,34 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
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

View file

@ -1,11 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
class AbstractPlugin(object):
"""This is base class for plugins"""
def __init__(self, arg):
super(AbstrackPlugin, self).__init__()
self.arg = arg

View file

@ -13,17 +13,6 @@ class Context(object):
def __init__(self): def __init__(self):
self.data = {} self.data = {}
self.scope = Scope().getInstance() 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): def put(self, var_name, data):
self.data[var_name] = data self.data[var_name] = data
@ -34,25 +23,6 @@ class Context(object):
def empty_data(self): def empty_data(self):
self.data = {} 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): def create_response(self, code=None, message=None, data=None, content_type=None):
self.data['responseCode'] = code self.data['responseCode'] = code
self.data['responseMessage'] = message self.data['responseMessage'] = message

View file

@ -0,0 +1,39 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
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')

View file

@ -6,8 +6,6 @@ import platform
import psutil import psutil
import cpuinfo import cpuinfo
import re import re
from uuid import getnode as get_mac
class System: class System:
class Process(object): class Process(object):
@ -101,6 +99,11 @@ class System:
def user_details(): def user_details():
return psutil.users() return psutil.users()
@staticmethod
def last_login_username():
#TODO
pass
class Os(object): class Os(object):
@staticmethod @staticmethod