Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / bin / runNS.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 #log files localization
24 #
25 import os, commands, sys, re, string, socket
26 from Utils_Identity import getShortHostName
27
28 if sys.platform == "win32":
29   # temporarily using home directory for Namning Service logs
30   # to be replaced with TEMP later...
31   os.environ["BaseDir"]=os.environ["HOME"]
32 else:
33   os.environ["BaseDir"]="/tmp"
34
35 os.environ["Username"]=os.environ["USER"]
36
37 # kill OmniNames if exists
38
39 #killall -q -9 omniNames
40
41 # clear log files
42
43 def startOmni():
44   try:
45     os.mkdir(os.environ["BaseDir"] + "/logs")
46     os.chmod(os.environ["BaseDir"] + "/logs", 0777)
47   except:
48     #print "Can't create " + os.environ["BaseDir"] + "/logs"
49     pass
50   
51   upath = os.environ["BaseDir"] + "/logs/" + os.environ["Username"]
52
53   try:
54     os.mkdir(upath)
55   except:
56     #print "Can't create " + upath
57     pass
58
59   #os.system("touch " + upath + "/dummy")
60   for fname in os.listdir(upath):
61     try:
62       if not fname.startswith("."): os.remove(upath + "/" + fname)
63     except:
64       pass
65   #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
66
67   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
74   print "hname=",hname
75   
76   f=open(os.environ["OMNIORB_CONFIG"])
77   ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
78   print "ss = ", ss
79   f.close()
80   aPort=re.findall("\d+", ss[0])[0]
81   
82   #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
83   #print "sed command = ", aSedCommand
84   #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
85   global process_id
86   print "port=", aPort
87   if sys.platform == "win32":          
88           #import win32pm
89           #command = ['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"']
90           #os.system("start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\"" )
91           command = "start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\""
92           #print command
93           pid = win32pm.spawnpid( string.join(command, " "), -nc )
94           process_id[pid]=command
95   else:
96     os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
97
98   print "ok"
99   print "to list contexts and objects bound into the context with the specified name : showNS "
100
101 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
102 #    computer if this Container does not exist. Default is localhost.
103 #    Others Containers are started with start_impl method of FactoryServer Container.
104 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
105 # Warning : on RedHat the file /etc/hosts contains by default a line like :
106 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
107 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
108 #   computers only if the computer name is removed on that line like :
109 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
110
111 # To start dynamically Containers on several computers you need to
112 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
113 # example : ORBInitRef NameService=corbaname::dm2s0017
114
115 # If you need to use several omniNames running on the same computer, you have to :
116 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
117 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
118 #2. start omninames with this port number in runNS.sh
119 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &