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