Subversion Repositories SmartDukaan

Rev

Rev 2926 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2926 Rev 3258
Line 1... Line 1...
1
'''
1
'''
2
Created on 25-Mar-2010
2
Created on 25-Mar-2010
3
 
3
 
4
@author: ashish
4
@author: ashish
5
'''
5
'''
6
import urlparse
-
 
7
from shop2020.thriftpy.config.ttypes import ConfigException
6
from shop2020.thriftpy.config.ttypes import ConfigException
8
from thrift.transport import TSocket
7
from thrift.transport import TSocket
9
from thrift.transport.TTransport import TFramedTransport
8
from thrift.transport.TTransport import TFramedTransport
10
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
9
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
11
from shop2020.thriftpy.config import Configuration
10
from shop2020.thriftpy.config import Configuration
12
 
11
 
13
class ConfigClient:
12
class ConfigClient:
14
    file_path = '/tmp/config.properties'
-
 
15
    
13
    
16
    def __init__(self):
14
    def __init__(self, host='localhost', port=9999):
17
        file = open(self.file_path)
-
 
18
        host = 'localhost'
-
 
19
        port = 9999
-
 
20
        
-
 
21
        if not file:
-
 
22
            self.host = 'localhost'
15
        self.host = host
23
            self.port = 9999
16
        self.port = port
24
        else:
-
 
25
            url = file.readline()
-
 
26
            file.close()
-
 
27
            if not url:
-
 
28
                self.host = 'localhost'
-
 
29
                self.port = 9999
-
 
30
                
-
 
31
            else :
-
 
32
                parsed_url = urlparse.urlparse(url)
-
 
33
                if parsed_url.hostname:
-
 
34
                    self.host = parsed_url.hostname
-
 
35
                if parsed_url.port:
-
 
36
                    self.port = parsed_url.port
-
 
37
        self.start_client()
17
        self.start_client()
38
    
18
    
39
    
-
 
40
    def start_client(self):
19
    def start_client(self):
41
        try:
20
        try:
42
            self.transport = TSocket.TSocket(self.host, self.port)
21
            self.transport = TSocket.TSocket(self.host, self.port)
43
            self.transport = TFramedTransport(self.transport)
22
            self.transport = TFramedTransport(self.transport)
44
            self.protocol = TBinaryProtocol(self.transport)
23
            self.protocol = TBinaryProtocol(self.transport)