Back to index

salome-kernel  6.5.0
runNS.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #  -*- coding: iso-8859-1 -*-
00003 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00004 #
00005 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00006 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00007 #
00008 # This library is free software; you can redistribute it and/or
00009 # modify it under the terms of the GNU Lesser General Public
00010 # License as published by the Free Software Foundation; either
00011 # version 2.1 of the License.
00012 #
00013 # This library is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 # Lesser General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU Lesser General Public
00019 # License along with this library; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00021 #
00022 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00023 #
00024 
00025 #log files localization
00026 #
00027 import os, commands, sys, re, string, socket
00028 from Utils_Identity import getShortHostName
00029 
00030 if sys.platform == "win32":
00031   # temporarily using home directory for Namning Service logs
00032   # to be replaced with TEMP later...
00033   os.environ["BaseDir"]=os.environ["HOME"]
00034 else:
00035   os.environ["BaseDir"]="/tmp"
00036 
00037 os.environ["Username"]=os.environ["USER"]
00038 
00039 # kill OmniNames if exists
00040 
00041 #killall -q -9 omniNames
00042 
00043 # clear log files
00044 
00045 def startOmni():
00046   try:
00047     os.mkdir(os.environ["BaseDir"] + "/logs")
00048     os.chmod(os.environ["BaseDir"] + "/logs", 0777)
00049   except:
00050     #print "Can't create " + os.environ["BaseDir"] + "/logs"
00051     pass
00052   
00053   upath = os.environ["BaseDir"] + "/logs/" + os.environ["Username"]
00054 
00055   try:
00056     os.mkdir(upath)
00057   except:
00058     #print "Can't create " + upath
00059     pass
00060 
00061   #os.system("touch " + upath + "/dummy")
00062   for fname in os.listdir(upath):
00063     try:
00064       if not fname.startswith("."): os.remove(upath + "/" + fname)
00065     except:
00066       pass
00067   #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
00068 
00069   print "Name Service... "
00070   #hname=os.environ["HOST"] #commands.getoutput("hostname")
00071   if sys.platform == "win32":
00072           hname=getShortHostName()
00073   else:
00074     hname=socket.gethostname()
00075 
00076   print "hname=",hname
00077   
00078   f=open(os.environ["OMNIORB_CONFIG"])
00079   ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
00080   print "ss = ", ss
00081   f.close()
00082   aPort=re.findall("\d+", ss[0])[0]
00083   
00084   #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
00085   #print "sed command = ", aSedCommand
00086   #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
00087   global process_id
00088   print "port=", aPort
00089   if sys.platform == "win32":          
00090           #import win32pm
00091           #command = ['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"']
00092           #os.system("start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\"" )
00093           command = "start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\""
00094           #print command
00095           pid = win32pm.spawnpid( string.join(command, " "), -nc )
00096           process_id[pid]=command
00097   else:
00098     os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
00099 
00100   print "ok"
00101   print "to list contexts and objects bound into the context with the specified name : showNS "
00102 
00103 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
00104 #    computer if this Container does not exist. Default is localhost.
00105 #    Others Containers are started with start_impl method of FactoryServer Container.
00106 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
00107 # Warning : on RedHat the file /etc/hosts contains by default a line like :
00108 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
00109 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
00110 #   computers only if the computer name is removed on that line like :
00111 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
00112 
00113 # To start dynamically Containers on several computers you need to
00114 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
00115 # example : ORBInitRef NameService=corbaname::dm2s0017
00116 
00117 # If you need to use several omniNames running on the same computer, you have to :
00118 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
00119 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
00120 #2. start omninames with this port number in runNS.sh
00121 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &