Subversion Repositories SmartDukaan

Rev

Rev 3252 | Rev 3915 | 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
 
3252 chandransh 28
    cfg_file_name = os.path.dirname(os.path.realpath(__file__)) + '/resources/shop2020.cfg'
3160 rajveer 29
 
3537 chandransh 30
    host = "localhost"
1292 vikas 31
    port = 9999
94 ashish 32
    for opt,arg in opts:
33
        if opt in ('-p', "--port"):
34
            port = arg;
35
        elif opt in ('-f', "--file"):
36
            cfg_file_name = arg
3130 rajveer 37
        elif opt in ('-e', "--env"):
38
            environment = arg
94 ashish 39
 
3537 chandransh 40
    start_server(cfg_file_name, host, port, environment)
94 ashish 41
 
3537 chandransh 42
def start_server(filename, host, port, environment):
3130 rajveer 43
    handler = ConfigServerHandler(filename, environment)
94 ashish 44
    processor = Configuration.Processor(handler)
3537 chandransh 45
    transport = TSocket.TServerSocket(host, port)
94 ashish 46
    tfactory = TTransport.TFramedTransportFactory()
47
    pfactory = TBinaryProtocolFactory()
48
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
1292 vikas 49
    print "Starting config server with config params, port "+ str(port)+" file "+ filename
94 ashish 50
    server.serve()
51
    print "Server functioning"
52
 
53
def usage():
3130 rajveer 54
    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 55
 
56
if __name__ == '__main__':
57
    main(sys.argv[1:])
58