Rev 2926 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 23-Feb-2010@author: ashish'''from shop2020.thriftpy.config.ttypes import ConfigExceptionimport osfrom ConfigParser import ConfigParser, NoSectionError, NoOptionErrorclass ConfigServerHandler:"""Implements Configserver stub from thrift."""def __init__(self, path_to_cfg, environment):"""Constructor takes file path info as parameter"""if os.path.exists(path_to_cfg) == False:self.cfg_path = '/tmp/shop2020.cfg'else:self.cfg_path = path_to_cfg#now load the configurationself.config_parser = ConfigParser()self.section_name = environmentself.initialized = False;try:read_ok = self.config_parser.read([self.cfg_path])except Exception, e:print e;#check if files have been read properlyfor filename in read_ok:if filename != self.cfg_path:raise IOError("File could not be read")else:self.initialized = Truedef getPropetry(self, propertyName):"""Parameters:- propertyName"""if self.initialized:try:return self.config_parser.get(self.section_name, propertyName)except NoSectionError:raise ConfigException(402, "config file is missing section 'Config'")except NoOptionError:raise ConfigException(402, "config file is missing option " + propertyName)else:raise ConfigException(401, "The config server is not properly initialized. Please try again later")def loadProperty(self, propertyName, propertyValue):"""Parameters:- propertyName- propertyValue"""if self.initialized:try:if propertyName == "":raise ConfigException(403, "property name is absent")self.config_parser.set(self.section_name, propertyName, propertyValue)except NoSectionError:raise ConfigException(402, "config file is missing section 'Config'")else:raise ConfigException(401, "The config server is not properly initialized. Please try again later")def reloadProperties(self):self.initialized = False;try:read_ok = self.config_parser.read([self.cfg_path])except Exception, e:print e;#check if files have been read properlyfor filename in read_ok:if filename != self.cfg_path:raise IOError("File could not be read")else:self.initialized = True