ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WEBCONDDB/CondWebServer/server.py
Revision: 1.9
Committed: Thu Jun 19 16:54:55 2008 UTC (16 years, 10 months ago) by xiezhen
Content type: text/x-python
Branch: MAIN
Changes since 1.8: +8 -7 lines
Log Message:
reset env instead of append

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.9 if k in ['PATH','LD_LIBRARY_PATH','TNS_ADMIN','ORACLE_HOME','ORA_NLS33','SEAL_PLUGINS','ROOTSYS','PYTHONPATH','NLS_DATE_FORMAT','NLS_LANG'] :
44     os.environ[k]=v
45     #if os.environ.has_key(k):
46     # #os.environ[k]+=':'+v
47     # os.environ[k]=v
48     #else:
49     # os.environ[k]=v
50     print k, os.environ[k]
51 xiezhen 1.1 os.chdir(currentdir)
52     def start (self):
53     """Start server
54     """
55     (options, args) = self.__parser.parse_args()
56     basedir=os.environ['HOME']
57     if options.basedir:
58     basedir=options.basedir
59     hostname='localhost'
60     if options.hostname:
61     hostname=options.hostname
62     port=8086
63     if options.port:
64     port=int(options.port)
65 xiezhen 1.2 cmsswversion=options.cmsswversion.strip(' ')
66 xiezhen 1.1 self.__setuprunenv(basedir,cmsswversion)
67 xiezhen 1.7
68     from Applications import iov,globaltag,serviceMap
69 xiezhen 1.1 serverconfig={'global':{'server.socket_host':hostname,'server.socket_port':port,'server.environment':'production'}}
70     cherrypy.config.update(serverconfig)
71     cherrypy.tree.mount(Root(),script_name='/')
72     currentdir=os.path.dirname(os.path.abspath(__file__))
73     appconfigfile=os.path.join(currentdir,'config','application.conf')
74 xiezhen 1.7 #print 'appconfigfile',appconfigfile
75 xiezhen 1.1 cherrypy.tree.mount(iov.IOV(appconfigfile),script_name='/iov')
76 xiezhen 1.4 detconfigfile=os.path.join(currentdir,'config','detector.conf')
77 xiezhen 1.7 #print 'detconfigfile',detconfigfile
78 xiezhen 1.4 cherrypy.tree.mount(serviceMap.serviceMap(detconfigfile),script_name='/serviceMap')
79 xiezhen 1.8 cherrypy.tree.mount(globaltag.GlobalTag(appconfigfile),script_name='/globaltag')
80 xiezhen 1.1 cherrypy.server.quickstart()
81     cherrypy.engine.start()
82    
83     if __name__ == '__main__':
84     s=Server()
85     s.start()
86    
87