Rev 3161 | Rev 3252 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 23-Feb-2010@author: ashish@author: rajveer'''import osimport sysfrom getopt import getopt, GetoptErrorfrom shop2020.config.impl.ConfigServerHandler import ConfigServerHandlerfrom thrift.protocol.TBinaryProtocol import TBinaryProtocolFactoryfrom shop2020.thriftpy.config import Configurationfrom thrift.transport import TSocket, TTransportfrom thrift.server import TServerdef main(argv):try:opts, args = getopt(argv,"p:f:e:", ["port=", "file=", "env="])except GetoptError:usage()sys.exit(2)try:environment = os.environ["ENV_TYPE"]except KeyError:environment = "DEV"cfg_file_name = os.environ["HOME"] + '/code/trunk/PyProj/src/shop2020/config/resources/shop2020.cfg'port = 9999for opt,arg in opts:if opt in ('-p', "--port"):port = arg;elif opt in ('-f', "--file"):cfg_file_name = argelif opt in ('-e', "--env"):environment = argstart_server(cfg_file_name, port, environment)def start_server(filename, port, environment):handler = ConfigServerHandler(filename, environment)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 "+ filenameserver.serve()print "Server functioning"def usage():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>'if __name__ == '__main__':main(sys.argv[1:])