Subversion Repositories SmartDukaan

Rev

Rev 2926 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 25-Mar-2010

@author: ashish
'''
from shop2020.thriftpy.config.ttypes import ConfigException
from thrift.transport import TSocket
from thrift.transport.TTransport import TFramedTransport
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
from shop2020.thriftpy.config import Configuration

class ConfigClient:
    
    def __init__(self, host='localhost', port=9999):
        self.host = host
        self.port = port
        self.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 client 
    try:
        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"