Subversion Repositories SmartDukaan

Rev

Rev 94 | Rev 1292 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 23-Feb-2010

@author: ashish
'''
import sys
from getopt import getopt, GetoptError
from shop2020.config.impl.ConfigServerHandler import ConfigServerHandler
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
from shop2020.thriftpy.config import Configuration
from thrift.transport import TSocket, TTransport
from thrift.server import TServer

port = 9999
cfg_file_name = '/tmp/shop2020.cfg'

def main(argv):
        
    try:
        opts, args = getopt(argv,"p:f:", ["port=", "file="])
    except GetoptError:
        usage()
        sys.exit(2)
    
    for opt,arg in opts:
        if opt in ('-p', "--port"):
            port = arg;
        elif opt in ('-f', "--file"):
            cfg_file_name = arg
    
    start_server()
    
def start_server():
    handler = ConfigServerHandler(cfg_file_name)
    processor = Configuration.Processor(handler)
    transport = TSocket.TServerSocket(port)
    tfactory = TTransport.TFramedTransportFactory()
    pfactory = TBinaryProtocolFactory()
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
    print "Starting config server with config params, port "+ str(port)+" file "+cfg_file_name
    server.serve()
    print "Server functioning"
    
def usage():
    print 'Usage: ConfigServer.py -p <port_to_run> -f <config_file_path> or ConfigServer.py --port=<port_to_run> --file=<config_file_path>' 

if __name__ == '__main__':
    main(sys.argv[1:])