Back to index

salome-kernel  6.5.0
nameserver.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 import sys, os, re, socket
00026 #import commands
00027 from server import *
00028 from Utils_Identity import getShortHostName
00029 from launchConfigureParser import verbose
00030 
00031 # -----------------------------------------------------------------------------
00032 
00033 class NamingServer(Server):
00034    XTERM=""
00035    USER=os.getenv('USER')
00036    if USER is None:
00037       USER='anonymous'
00038    #os.system("mkdir -m 777 -p /tmp/logs")
00039    LOGDIR="/tmp/logs/" + USER
00040 
00041    def initNSArgs(self):
00042         if sys.platform == "win32":
00043           # temporarily using home directory for Namning Service logs
00044           # to be replaced with TEMP later...
00045           os.environ["BaseDir"]=os.environ["HOME"]
00046         else:
00047           os.environ["BaseDir"]="/tmp"
00048 
00049         try:
00050           os.mkdir(os.environ["BaseDir"] + "/logs")
00051           os.chmod(os.environ["BaseDir"] + "/logs", 0777)
00052         except:
00053           #print "Can't create " + os.environ["BaseDir"] + "/logs"
00054           pass
00055 
00056         upath = os.environ["BaseDir"] + "/logs/";
00057         if sys.platform == "win32":
00058            upath += os.environ["Username"];
00059         else:
00060            upath += os.environ["USER"];
00061 
00062         try:
00063           os.mkdir(upath)
00064         except:
00065           #print "Can't create " + upath
00066           pass
00067 
00068         if verbose(): print "Name Service... ",
00069         #hname=os.environ["HOST"] #commands.getoutput("hostname")
00070         if sys.platform == "win32":
00071           hname=getShortHostName();
00072         else:
00073           hname = socket.gethostname();
00074         #print "hname=",hname
00075 
00076         f=open(os.environ["OMNIORB_CONFIG"])
00077         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
00078         if verbose(): print "ss = ", ss,
00079         f.close()
00080         sl=ss[0]
00081         ll = sl.split(':')
00082         aPort = ll[-1]
00083         #aPort=(ss.join().split(':'))[2];
00084         #aPort=re.findall("\d+", ss[0])[0]
00085 
00086         # \begin{E.A.}
00087         # put the log files of omniNames in different directory with port reference,
00088         # it is cleaner on linux and it is a fix for salome since it is impossible to
00089         # remove the log files if the corresponding omniNames has not been killed.
00090         # \end{E.A.}
00091         
00092         upath += "/omniNames_%s"%(aPort)
00093         try:
00094            os.mkdir(upath)
00095         except:
00096            #print "Can't create " + upath
00097            pass
00098         
00099         #os.system("touch " + upath + "/dummy")
00100         for fname in os.listdir(upath):
00101           try:
00102              os.remove(upath + "/" + fname)
00103           except:
00104             pass
00105         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
00106 
00107         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
00108         #print "sed command = ", aSedCommand
00109         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
00110         #print "port=", aPort
00111         if sys.platform == "win32":
00112           #print "start omniNames -start " + aPort + " -logdir " + upath
00113           self.CMD=['omniNames -start ' , aPort , ' -nohostname ', ' -logdir ' , '\"' + upath + '\"', ' -errlog', '\"' + upath+'/omniNameErrors.log' + '\"']
00114           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
00115         else:
00116           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
00117           self.CMD=['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
00118           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
00119 
00120         if verbose(): print "... ok"
00121         if verbose(): print "to list contexts and objects bound into the context with the specified name : showNS "
00122 
00123 
00124    def initArgs(self):
00125         Server.initArgs(self)
00126         if sys.platform == "win32":
00127           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
00128         else:
00129           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
00130         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
00131         self.initNSArgs()
00132 
00133 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
00134 #    computer if this Container does not exist. Default is localhost.
00135 #    Others Containers are started with start_impl method of FactoryServer Container.
00136 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
00137 # Warning : on RedHat the file /etc/hosts contains by default a line like :
00138 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
00139 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
00140 #   computers only if the computer name is removed on that line like :
00141 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
00142 
00143 # To start dynamically Containers on several computers you need to
00144 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
00145 # example : ORBInitRef NameService=corbaname::dm2s0017
00146 
00147 # If you need to use several omniNames running on the same computer, you have to :
00148 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
00149 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
00150 #2. start omninames with this port number like in orbmodile.py
00151 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &