Subversion Repositories SmartDukaan

Rev

Rev 100 | Rev 3130 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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