ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WEBCONDDB/CondWebServer/server.py
Revision: 1.6
Committed: Fri May 9 14:15:21 2008 UTC (16 years, 11 months ago) by xiezhen
Content type: text/x-python
Branch: MAIN
CVS Tags: V01-04-01, V01-04-00, V01-03-00, V01-02-02, V01-02-01
Changes since 1.5: +2 -0 lines
Log Message:
update

File Contents

# User Rev Content
1 xiezhen 1.1 import os, sys
2     import cherrypy
3     from optparse import OptionParser
4 xiezhen 1.5 from Applications import iov,serviceMap
5 xiezhen 1.1 class Root(object):
6     @cherrypy.expose
7     def index(self):
8     """ Top level page
9     """
10     return "This is Cond DB Application Server"
11    
12     class Server(object):
13     def __init__(self):
14     """Constructor
15     """
16     self.__parser=OptionParser()
17     self.__parser.add_option("--basedir",action="store",dest="basedir",
18     help="application base installation dir default $HOME")
19     self.__parser.add_option("--hostname",action="store",dest="hostname",
20     help="hostname default localhost")
21     self.__parser.add_option("-p","--port",action="store",dest="port",
22     help="port default 8086")
23     self.__parser.add_option("","--cmsswversion",action="store",
24     dest="cmsswversion", help="cmsswversion(required)")
25     self.__platform='slc4_ia32_gcc345'
26    
27     def __setuprunenv(self,basedir,cmsswversion):
28     """Set up cmssw running environment according to installation location and cmssw version
29     """
30     cmsswlocation=os.path.join(basedir,self.__platform,'cms','cmssw',cmsswversion)
31     currentdir=os.path.dirname(os.path.abspath(__file__))
32     os.chdir(cmsswlocation)
33     stdout_handle = os.popen('scramv1 runtime -sh', 'r')
34     text=stdout_handle.read()
35     new_string = ''
36     for line in text.split('\n'):
37     if line.strip():
38     new_string += line
39     new_string=new_string.replace('export ',' ').strip(';')
40     new_string=new_string.replace('; ',' ').strip(' ')
41     for env in new_string.split('" '):
42     (k,v)=env.split('="')
43 xiezhen 1.3 if k in ['PATH','LD_LIBRARY_PATH','TNS_ADMIN','ORACLE_HOME','ORA_NLS33','SEAL_PLUGINS','ROOTSYS'] :
44 xiezhen 1.2 if os.environ.has_key(k):
45     os.environ[k]+=':'+v
46     else:
47     os.environ[k]=v
48 xiezhen 1.1 os.chdir(currentdir)
49     def start (self):
50     """Start server
51     """
52     (options, args) = self.__parser.parse_args()
53     basedir=os.environ['HOME']
54     if options.basedir:
55     basedir=options.basedir
56     hostname='localhost'
57     if options.hostname:
58     hostname=options.hostname
59     port=8086
60     if options.port:
61     port=int(options.port)
62 xiezhen 1.2 cmsswversion=options.cmsswversion.strip(' ')
63 xiezhen 1.1 self.__setuprunenv(basedir,cmsswversion)
64     serverconfig={'global':{'server.socket_host':hostname,'server.socket_port':port,'server.environment':'production'}}
65     cherrypy.config.update(serverconfig)
66     cherrypy.tree.mount(Root(),script_name='/')
67     currentdir=os.path.dirname(os.path.abspath(__file__))
68     appconfigfile=os.path.join(currentdir,'config','application.conf')
69 xiezhen 1.6 print 'appconfigfile',appconfigfile
70 xiezhen 1.1 cherrypy.tree.mount(iov.IOV(appconfigfile),script_name='/iov')
71 xiezhen 1.4 detconfigfile=os.path.join(currentdir,'config','detector.conf')
72 xiezhen 1.6 print 'detconfigfile',detconfigfile
73 xiezhen 1.4 cherrypy.tree.mount(serviceMap.serviceMap(detconfigfile),script_name='/serviceMap')
74 xiezhen 1.1 cherrypy.server.quickstart()
75     cherrypy.engine.start()
76    
77     if __name__ == '__main__':
78     s=Server()
79     s.start()
80    
81