Subversion Repositories SmartDukaan

Rev

Rev 3161 | Rev 3252 | 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
def main(argv):
16
 
17
    try:
3181 rajveer 18
        opts, args = getopt(argv,"p:f:e:", ["port=", "file=", "env="])
94 ashish 19
    except GetoptError:
20
        usage()
21
        sys.exit(2)
1292 vikas 22
 
3130 rajveer 23
    try:
24
        environment = os.environ["ENV_TYPE"]
25
    except KeyError:
26
        environment = "DEV"
3160 rajveer 27
 
3161 rajveer 28
    cfg_file_name = os.environ["HOME"] + '/code/trunk/PyProj/src/shop2020/config/resources/shop2020.cfg'
3160 rajveer 29
 
1292 vikas 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