ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WEBCONDDB/CondWebServer/server.py
Revision: 1.7
Committed: Wed Jun 18 13:17:49 2008 UTC (16 years, 10 months ago) by xiezhen
Content type: text/x-python
Branch: MAIN
Changes since 1.6: +9 -4 lines
Log Message:
added globaltag

File Contents

# User Rev Content
1 xiezhen 1.1 import os, sys
2     import cherrypy
3     from optparse import OptionParser
4     class Root(object):
5     @cherrypy.expose
6     def index(self):
7     """ Top level page
8     """
9     return "This is Cond DB Application Server"
10    
11     class Server(object):
12     def __init__(self):
13     """Constructor
14     """
15     self.__parser=OptionParser()
16     self.__parser.add_option("--basedir",action="store",dest="basedir",
17     help="application base installation dir default $HOME")
18     self.__parser.add_option("--hostname",action="store",dest="hostname",
19     help="hostname default localhost")
20     self.__parser.add_option("-p","--port",action="store",dest="port",
21     help="port default 8086")
22     self.__parser.add_option("","--cmsswversion",action="store",
23     dest="cmsswversion", help="cmsswversion(required)")
24     self.__platform='slc4_ia32_gcc345'
25    
26     def __setuprunenv(self,basedir,cmsswversion):
27     """Set up cmssw running environment according to installation location and cmssw version
28     """
29     cmsswlocation=os.path.join(basedir,self.__platform,'cms','cmssw',cmsswversion)
30     currentdir=os.path.dirname(os.path.abspath(__file__))
31 xiezhen 1.7 print 'cmsswlocation',cmsswlocation
32 xiezhen 1.1 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.7 if k in ['PATH','LD_LIBRARY_PATH','TNS_ADMIN','ORACLE_HOME','ORA_NLS33','SEAL_PLUGINS','ROOTSYS','PYTHONPATH'] :
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.7 if k=='PYTHONPATH':
49     print os.environ[k]
50 xiezhen 1.1 os.chdir(currentdir)
51     def start (self):
52     """Start server
53     """
54     (options, args) = self.__parser.parse_args()
55     basedir=os.environ['HOME']
56     if options.basedir:
57     basedir=options.basedir
58     hostname='localhost'
59     if options.hostname:
60     hostname=options.hostname
61     port=8086
62     if options.port:
63     port=int(options.port)
64 xiezhen 1.2 cmsswversion=options.cmsswversion.strip(' ')
65 xiezhen 1.1 self.__setuprunenv(basedir,cmsswversion)
66 xiezhen 1.7
67     from Applications import iov,globaltag,serviceMap
68 xiezhen 1.1 serverconfig={'global':{'server.socket_host':hostname,'server.socket_port':port,'server.environment':'production'}}
69     cherrypy.config.update(serverconfig)
70     cherrypy.tree.mount(Root(),script_name='/')
71     currentdir=os.path.dirname(os.path.abspath(__file__))
72     appconfigfile=os.path.join(currentdir,'config','application.conf')
73 xiezhen 1.7 #print 'appconfigfile',appconfigfile
74 xiezhen 1.1 cherrypy.tree.mount(iov.IOV(appconfigfile),script_name='/iov')
75 xiezhen 1.4 detconfigfile=os.path.join(currentdir,'config','detector.conf')
76 xiezhen 1.7 #print 'detconfigfile',detconfigfile
77 xiezhen 1.4 cherrypy.tree.mount(serviceMap.serviceMap(detconfigfile),script_name='/serviceMap')
78 xiezhen 1.7 cherrypy.tree.mount(globaltag.GlobalTag(),script_name='/globaltag')
79 xiezhen 1.1 cherrypy.server.quickstart()
80     cherrypy.engine.start()
81    
82     if __name__ == '__main__':
83     s=Server()
84     s.start()
85    
86