Salome HOME
Update from BR_V5_DEV 13feb09
[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         #os.system("touch " + upath + "/dummy")
67         for fname in os.listdir(upath):
68           try:
69             if not fname.startswith("."): os.remove(upath + "/" + fname)
70           except:
71             pass
72         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
73
74         if verbose(): print "Name Service... ",
75         #hname=os.environ["HOST"] #commands.getoutput("hostname")
76         if sys.platform == "win32":
77           hname=getShortHostName();
78         else:
79           hname = socket.gethostname();
80         #print "hname=",hname
81
82         f=open(os.environ["OMNIORB_CONFIG"])
83         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
84         if verbose(): print "ss = ", ss,
85         f.close()
86         sl=ss[0]
87         ll = sl.split(':')
88         aPort = ll[-1]
89         #aPort=(ss.join().split(':'))[2];
90         #aPort=re.findall("\d+", ss[0])[0]
91
92         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
93         #print "sed command = ", aSedCommand
94         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
95         #print "port=", aPort
96         if sys.platform == "win32":
97           #print "start omniNames -start " + aPort + " -logdir " + upath
98           self.CMD=['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"', ' -errlog', '\"' + upath+'/omniNameErrors.log' + '\"']
99           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
100         else:
101           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
102           self.CMD=['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
103           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
104
105         if verbose(): print "... ok"
106         if verbose(): print "to list contexts and objects bound into the context with the specified name : showNS "
107
108
109    def initArgs(self):
110         Server.initArgs(self)
111         if sys.platform == "win32":
112           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
113         else:
114           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
115         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
116         self.initNSArgs()
117
118 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
119 #    computer if this Container does not exist. Default is localhost.
120 #    Others Containers are started with start_impl method of FactoryServer Container.
121 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
122 # Warning : on RedHat the file /etc/hosts contains by default a line like :
123 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
124 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
125 #   computers only if the computer name is removed on that line like :
126 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
127
128 # To start dynamically Containers on several computers you need to
129 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
130 # example : ORBInitRef NameService=corbaname::dm2s0017
131
132 # If you need to use several omniNames running on the same computer, you have to :
133 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
134 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
135 #2. start omninames with this port number like in orbmodile.py
136 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &