Rev 94 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 25-Mar-2010@author: ashish'''import urlparsefrom shop2020.thriftpy.config.ttypes import ConfigExceptionfrom thrift.transport import TSocketfrom thrift.transport.TTransport import TFramedTransportfrom thrift.protocol.TBinaryProtocol import TBinaryProtocolfrom shop2020.thriftpy.config import Configurationclass ConfigClient:file_path = '/tmp/config.properties'def __init__(self):file = open(self.file_path)host = 'localhost'port = 9999if not file:self.host = 'localhost'self.port = 9999else:url = file.readline()file.close()if not url:self.host = 'localhost'self.port = 9999else :parsed_url = urlparse.urlparse(url)if parsed_url.hostname:self.host = parsed_url.hostnameif parsed_url.port:self.port = parsed_url.portself.start_client()def start_client(self):try:self.transport = TSocket.TSocket(self.host, self.port)self.transport = TFramedTransport(self.transport)self.protocol = TBinaryProtocol(self.transport)self.client = Configuration.Client(self.protocol)self.transport.open()except:raise ConfigException(101, 'unable to load the client')def get_property(self, key):return self.client.getPropetry(key)def set_property(self, key, value):return self.client.loadProperty(key, value)def reloadProperties(self):return self.client.reloadProperties()if __name__ == '__main__':#test config clienttry:config_client = ConfigClient()print config_client.get_property("export_entities_path")config_client.set_property('export_entities_path', 'abc')print config_client.get_property("export_entities_path")config_client.reloadProperties()print config_client.get_property('export_entities_path')except:print "error while putting up config client"