Salome HOME
To see which hdf5 we're using in configure log
[modules/kernel.git] / bin / nameserver.py
1 #!/usr/bin/env python
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 import sys, os, re, socket
24 #import commands
25 from server import *
26 from Utils_Identity import getShortHostName
27 from launchConfigureParser import verbose
28
29 # -----------------------------------------------------------------------------
30
31 class NamingServer(Server):
32    XTERM=""
33    USER=os.getenv('USER')
34    if USER is None:
35       USER='anonymous'
36    #os.system("mkdir -m 777 -p /tmp/logs")
37    LOGDIR="/tmp/logs/" + USER
38
39    def initNSArgs(self):
40         if sys.platform == "win32":
41           # temporarily using home directory for Namning Service logs
42           # to be replaced with TEMP later...
43           os.environ["BaseDir"]=os.environ["HOME"]
44         else:
45           os.environ["BaseDir"]="/tmp"
46
47         try:
48           os.mkdir(os.environ["BaseDir"] + "/logs")
49           os.chmod(os.environ["BaseDir"] + "/logs", 0777)
50         except:
51           #print "Can't create " + os.environ["BaseDir"] + "/logs"
52           pass
53
54         upath = os.environ["BaseDir"] + "/logs/";
55         if sys.platform == "win32":
56            upath += os.environ["Username"];
57         else:
58            upath += os.environ["USER"];
59
60         try:
61           os.mkdir(upath)
62         except:
63           #print "Can't create " + upath
64           pass
65
66         if verbose(): print "Name Service... ",
67         #hname=os.environ["HOST"] #commands.getoutput("hostname")
68         if sys.platform == "win32":
69           hname=getShortHostName();
70         else:
71           hname = socket.gethostname();
72         #print "hname=",hname
73
74         f=open(os.environ["OMNIORB_CONFIG"])
75         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
76         if verbose(): print "ss = ", ss,
77         f.close()
78         sl=ss[0]
79         ll = sl.split(':')
80         aPort = ll[-1]
81         #aPort=(ss.join().split(':'))[2];
82         #aPort=re.findall("\d+", ss[0])[0]
83
84         # \begin{E.A.}
85         # put the log files of omniNames in different directory with port reference,
86         # it is cleaner on linux and it is a fix for salome since it is impossible to
87         # remove the log files if the corresponding omniNames has not been killed.
88         # \end{E.A.}
89         
90         upath += "/omniNames_%s"%(aPort)
91         try:
92            os.mkdir(upath)
93         except:
94            #print "Can't create " + upath
95            pass
96         
97         #os.system("touch " + upath + "/dummy")
98         for fname in os.listdir(upath):
99           try:
100              os.remove(upath + "/" + fname)
101           except:
102             pass
103         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
104
105         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
106         #print "sed command = ", aSedCommand
107         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
108         #print "port=", aPort
109         if sys.platform == "win32":
110           #print "start omniNames -start " + aPort + " -logdir " + upath
111           self.CMD=['omniNames -start ' , aPort , ' -nohostname ', ' -logdir ' , '\"' + upath + '\"', ' -errlog', '\"' + upath+'/omniNameErrors.log' + '\"']
112           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
113         else:
114           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
115           self.CMD=['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
116           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
117
118         if verbose(): print "... ok"
119         if verbose(): print "to list contexts and objects bound into the context with the specified name : showNS "
120
121
122    def initArgs(self):
123         Server.initArgs(self)
124         if sys.platform == "win32":
125           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
126         else:
127           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
128         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
129         self.initNSArgs()
130
131 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
132 #    computer if this Container does not exist. Default is localhost.
133 #    Others Containers are started with start_impl method of FactoryServer Container.
134 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
135 # Warning : on RedHat the file /etc/hosts contains by default a line like :
136 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
137 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
138 #   computers only if the computer name is removed on that line like :
139 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
140
141 # To start dynamically Containers on several computers you need to
142 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
143 # example : ORBInitRef NameService=corbaname::dm2s0017
144
145 # If you need to use several omniNames running on the same computer, you have to :
146 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
147 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
148 #2. start omninames with this port number like in orbmodile.py
149 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &