Subversion Repositories SmartDukaan

Rev

Rev 100 | Rev 3130 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 100 Rev 1292
Line 9... Line 9...
9
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
9
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
10
from shop2020.thriftpy.config import Configuration
10
from shop2020.thriftpy.config import Configuration
11
from thrift.transport import TSocket, TTransport
11
from thrift.transport import TSocket, TTransport
12
from thrift.server import TServer
12
from thrift.server import TServer
13
 
13
 
14
port = 9999
-
 
15
cfg_file_name = '/tmp/shop2020.cfg'
-
 
16
 
-
 
17
def main(argv):
14
def main(argv):
18
        
15
        
19
    try:
16
    try:
20
        opts, args = getopt(argv,"p:f:", ["port=", "file="])
17
        opts, args = getopt(argv,"p:f:", ["port=", "file="])
21
    except GetoptError:
18
    except GetoptError:
22
        usage()
19
        usage()
23
        sys.exit(2)
20
        sys.exit(2)
-
 
21
 
-
 
22
    cfg_file_name = '/tmp/shop2020.cfg'
24
    
23
    port = 9999
25
    for opt,arg in opts:
24
    for opt,arg in opts:
26
        if opt in ('-p', "--port"):
25
        if opt in ('-p', "--port"):
27
            port = arg;
26
            port = arg;
28
        elif opt in ('-f', "--file"):
27
        elif opt in ('-f', "--file"):
29
            cfg_file_name = arg
28
            cfg_file_name = arg
30
    
29
    
31
    start_server()
30
    start_server(cfg_file_name, port)
32
    
31
    
33
def start_server():
32
def start_server(filename, port):
34
    handler = ConfigServerHandler(cfg_file_name)
33
    handler = ConfigServerHandler(filename)
35
    processor = Configuration.Processor(handler)
34
    processor = Configuration.Processor(handler)
36
    transport = TSocket.TServerSocket(port)
35
    transport = TSocket.TServerSocket(port)
37
    tfactory = TTransport.TFramedTransportFactory()
36
    tfactory = TTransport.TFramedTransportFactory()
38
    pfactory = TBinaryProtocolFactory()
37
    pfactory = TBinaryProtocolFactory()
39
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
38
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
40
    print "Starting config server with config params, port "+ str(port)+" file "+cfg_file_name
39
    print "Starting config server with config params, port "+ str(port)+" file "+ filename
41
    server.serve()
40
    server.serve()
42
    print "Server functioning"
41
    print "Server functioning"
43
    
42
    
44
def usage():
43
def usage():
45
    print 'Usage: ConfigServer.py -p <port_to_run> -f <config_file_path> or ConfigServer.py --port=<port_to_run> --file=<config_file_path>' 
44
    print 'Usage: ConfigServer.py -p <port_to_run> -f <config_file_path> or ConfigServer.py --port=<port_to_run> --file=<config_file_path>'