Subversion Repositories SmartDukaan

Rev

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