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