| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 25-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
|
|
7 |
from thrift.transport import TSocket
|
|
|
8 |
from thrift.transport.TTransport import TFramedTransport
|
|
|
9 |
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
|
|
|
10 |
from shop2020.thriftpy.config import Configuration
|
|
|
11 |
|
|
|
12 |
class ConfigClient:
|
|
|
13 |
|
| 3258 |
rajveer |
14 |
def __init__(self, host='localhost', port=9999):
|
|
|
15 |
self.host = host
|
|
|
16 |
self.port = port
|
| 94 |
ashish |
17 |
self.start_client()
|
|
|
18 |
|
|
|
19 |
def start_client(self):
|
|
|
20 |
try:
|
|
|
21 |
self.transport = TSocket.TSocket(self.host, self.port)
|
|
|
22 |
self.transport = TFramedTransport(self.transport)
|
|
|
23 |
self.protocol = TBinaryProtocol(self.transport)
|
|
|
24 |
self.client = Configuration.Client(self.protocol)
|
|
|
25 |
self.transport.open()
|
|
|
26 |
except:
|
|
|
27 |
raise ConfigException(101, 'unable to load the client')
|
|
|
28 |
|
|
|
29 |
def get_property(self, key):
|
|
|
30 |
return self.client.getPropetry(key)
|
|
|
31 |
|
|
|
32 |
def set_property(self, key, value):
|
|
|
33 |
return self.client.loadProperty(key, value)
|
|
|
34 |
|
| 2926 |
rajveer |
35 |
def reloadProperties(self):
|
|
|
36 |
return self.client.reloadProperties()
|
| 94 |
ashish |
37 |
|
| 2926 |
rajveer |
38 |
|
| 94 |
ashish |
39 |
if __name__ == '__main__':
|
|
|
40 |
#test config client
|
|
|
41 |
try:
|
|
|
42 |
config_client = ConfigClient()
|
| 2926 |
rajveer |
43 |
print config_client.get_property("export_entities_path")
|
|
|
44 |
config_client.set_property('export_entities_path', 'abc')
|
|
|
45 |
print config_client.get_property("export_entities_path")
|
|
|
46 |
config_client.reloadProperties()
|
|
|
47 |
print config_client.get_property('export_entities_path')
|
| 94 |
ashish |
48 |
except:
|
| 2926 |
rajveer |
49 |
print "error while putting up config client"
|