scope implemented

This commit is contained in:
İsmail Başaran 2016-02-21 03:24:54 +02:00
parent 79b8b083f1
commit b44e46d20f
3 changed files with 47 additions and 8 deletions

23
opt/ahenk/base/Scope.py Normal file
View file

@ -0,0 +1,23 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
class Scope(object):
"""docstring for Scope"""
def __init__(self):
super(Scope, self).__init__()
self.customMap = {}
self.configurationManager=None
def getCustomMap(self):
return self.customMap
def putCustomMap(self,name,value):
self.custom[name]=value
def getConfigurationManager(self):
return self.configurationManager
def serConfigurationManager(self,configurationManager):
self.configurationManager = configurationManager

View file

@ -4,17 +4,29 @@
import logging
import logging.config
from ahenkd import AhenkDeamon
class Logger(object):
"""docstring for Logger"""
def __init__(self, logfilepath, loglevel):
def __init__(self):
super(Logger, self).__init__()
logging.config.fileConfig('logging.conf')
self.logger = logging.basicConfig(filename=logfilepath,level=loglevel)
scope = AhenkDeamon.scope()
configManager = scope.getConfigurationManager()
logging.config.fileConfig(configManager.get('BASE','logConfigurationFilePath'))
self.logger = logging.getLogger()
def getLogger(self):
return self.logger
def info(self,logstring):
self.logger.info(logstring)
def warning(self,logstring):
self.logger.warning(logstring)
self.logger.warning(logstring)
def error(self,logstring):
self.logger.error(logstring)
def debug(self,logstring):
self.logger.debug(logstring)

View file

@ -6,6 +6,7 @@
import configparser
import slixmpp
from slixmpp.exceptions import IqError, IqTimeout
from ahenkd import AhenkDeamon
"""
--fetch parameters of connection from conf file
@ -24,13 +25,16 @@ from slixmpp.exceptions import IqError, IqTimeout
class Messaging(slixmpp.ClientXMPP):
def __init__(self,configurationManager,logger):
def __init__(self):
# global scope of ahenk
scope = AhenkDeamon.scope()
# logger comes from ahenk deamon
self.logger = logger
self.logger = scope.getLogger()
# configurationManager comes from ahenk deamon
self.configurationManager = configurationManager
self.configurationManager = scope.getConfigurationManager()
#set parameters
slixmpp.ClientXMPP.__init__(self, self.configurationManager.get('CONNECTION', 'jid'), self.configurationManager.get('Connection_Param', 'password'))