Subversion Repositories SmartDukaan

Rev

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

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