Salome HOME
Improve SALOMEDS attributes interfaces:
[modules/kernel.git] / bin / nameserver.py
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2008  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 import sys, os, re, socket
25 #import commands
26 from server import *
27 from Utils_Identity import getShortHostName
28 from launchConfigureParser import verbose
29
30 # -----------------------------------------------------------------------------
31
32 class NamingServer(Server):
33    XTERM=""
34    USER=os.getenv('USER')
35    if USER is None:
36       USER='anonymous'
37    #os.system("mkdir -m 777 -p /tmp/logs")
38    LOGDIR="/tmp/logs/" + USER
39
40    def initNSArgs(self):
41         if sys.platform == "win32":
42           # temporarily using home directory for Namning Service logs
43           # to be replaced with TEMP later...
44           os.environ["BaseDir"]=os.environ["HOME"]
45         else:
46           os.environ["BaseDir"]="/tmp"
47
48         try:
49           os.mkdir(os.environ["BaseDir"] + "/logs")
50           os.chmod(os.environ["BaseDir"] + "/logs", 0777)
51         except:
52           #print "Can't create " + os.environ["BaseDir"] + "/logs"
53           pass
54
55         upath = os.environ["BaseDir"] + "/logs/";
56         if sys.platform == "win32":
57            upath += os.environ["Username"];
58         else:
59            upath += os.environ["USER"];
60
61         try:
62           os.mkdir(upath)
63         except:
64           #print "Can't create " + upath
65           pass
66
67         if verbose(): print "Name Service... ",
68         #hname=os.environ["HOST"] #commands.getoutput("hostname")
69         if sys.platform == "win32":
70           hname=getShortHostName();
71         else:
72           hname = socket.gethostname();
73         #print "hname=",hname
74
75         f=open(os.environ["OMNIORB_CONFIG"])
76         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
77         if verbose(): print "ss = ", ss,
78         f.close()
79         sl=ss[0]
80         ll = sl.split(':')
81         aPort = ll[-1]
82         #aPort=(ss.join().split(':'))[2];
83         #aPort=re.findall("\d+", ss[0])[0]
84
85         # \begin{E.A.}
86         # put the log files of omniNames in different directory with port reference,
87         # it is cleaner on linux and it is a fix for salome since it is impossible to
88         # remove the log files if the corresponding omniNames has not been killed.
89         # \end{E.A.}
90         
91         upath += "/omniNames_%s"%(aPort)
92         try:
93            os.mkdir(upath)
94         except:
95            #print "Can't create " + upath
96            pass
97         
98         #os.system("touch " + upath + "/dummy")
99         for fname in os.listdir(upath):
100           try:
101              os.remove(upath + "/" + fname)
102           except:
103             pass
104         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
105
106         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
107         #print "sed command = ", aSedCommand
108         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
109         #print "port=", aPort
110         if sys.platform == "win32":
111           #print "start omniNames -start " + aPort + " -logdir " + upath
112           self.CMD=['omniNames -start ' , aPort , ' -nohostname ', ' -logdir ' , '\"' + upath + '\"', ' -errlog', '\"' + upath+'/omniNameErrors.log' + '\"']
113           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
114         else:
115           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
116           self.CMD=['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
117           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
118
119         if verbose(): print "... ok"
120         if verbose(): print "to list contexts and objects bound into the context with the specified name : showNS "
121
122
123    def initArgs(self):
124         Server.initArgs(self)
125         if sys.platform == "win32":
126           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
127         else:
128           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
129         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
130         self.initNSArgs()
131
132 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
133 #    computer if this Container does not exist. Default is localhost.
134 #    Others Containers are started with start_impl method of FactoryServer Container.
135 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
136 # Warning : on RedHat the file /etc/hosts contains by default a line like :
137 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
138 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
139 #   computers only if the computer name is removed on that line like :
140 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
141
142 # To start dynamically Containers on several computers you need to
143 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
144 # example : ORBInitRef NameService=corbaname::dm2s0017
145
146 # If you need to use several omniNames running on the same computer, you have to :
147 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
148 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
149 #2. start omninames with this port number like in orbmodile.py
150 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &