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
import logging.config import logging.config
from ahenkd import AhenkDeamon
class Logger(object): class Logger(object):
"""docstring for Logger""" """docstring for Logger"""
def __init__(self, logfilepath, loglevel): def __init__(self):
super(Logger, self).__init__() super(Logger, self).__init__()
logging.config.fileConfig('logging.conf') scope = AhenkDeamon.scope()
self.logger = logging.basicConfig(filename=logfilepath,level=loglevel) configManager = scope.getConfigurationManager()
logging.config.fileConfig(configManager.get('BASE','logConfigurationFilePath'))
self.logger = logging.getLogger()
def getLogger(self):
return self.logger
def info(self,logstring): def info(self,logstring):
self.logger.info(logstring) self.logger.info(logstring)
def warning(self,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 configparser
import slixmpp import slixmpp
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
from ahenkd import AhenkDeamon
""" """
--fetch parameters of connection from conf file --fetch parameters of connection from conf file
@ -24,13 +25,16 @@ from slixmpp.exceptions import IqError, IqTimeout
class Messaging(slixmpp.ClientXMPP): class Messaging(slixmpp.ClientXMPP):
def __init__(self,configurationManager,logger): def __init__(self):
# global scope of ahenk
scope = AhenkDeamon.scope()
# logger comes from ahenk deamon # logger comes from ahenk deamon
self.logger = logger self.logger = scope.getLogger()
# configurationManager comes from ahenk deamon # configurationManager comes from ahenk deamon
self.configurationManager = configurationManager self.configurationManager = scope.getConfigurationManager()
#set parameters #set parameters
slixmpp.ClientXMPP.__init__(self, self.configurationManager.get('CONNECTION', 'jid'), self.configurationManager.get('Connection_Param', 'password')) slixmpp.ClientXMPP.__init__(self, self.configurationManager.get('CONNECTION', 'jid'), self.configurationManager.get('Connection_Param', 'password'))