Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
155 ashish 1
'''
2
Created on 17-May-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.config.client.ConfigClient import ConfigClient
7
from shop2020.utils.Utils import log_entry
8
from thrift.transport.TSocket import TSocket
9
from thrift.transport.TTransport import TFramedTransport
10
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
11
from shop2020.thriftpy.model.v1.shoppingcart import ShoppingCartService
12
class ShoppingCartClient:
13
 
14
    host = "localhost"
15
    port = "9003"
16
 
17
    def __init__(self):
18
        try:
19
            self.config_client = ConfigClient()
20
            self.host = self.config_client.get_property("shopping_cart_hostname")
21
            self.host = self.config_client.get_property("shopping_cart_port")
304 ashish 22
            self.__start__()
155 ashish 23
        except:
24
            log_entry("error getting data from config")
25
 
26
    def __start__(self):
27
        self.transport = TSocket(self.host, self.port)
28
        self.transport = TFramedTransport(self.transport)
29
        self.protocol = TBinaryProtocol(self.transport)    
30
        self.client = ShoppingCartService.Client(self.protocol)
31
        self.transport.open()
32
 
33
    def get_client(self):
434 ashish 34
        if self.transport.isOpen():
35
            return self.client
36
        self.transport.open()
155 ashish 37
        return self.client