Back to index

salome-kernel  6.5.0
launchSalome.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 socket
00026 import os
00027 import sys
00028 import shutil
00029 
00030 #####################################################################
00031 def findFreePort(startPort, step) :
00032 
00033     currentPort = startPort;
00034     if step < 1:
00035         step = 1;
00036 
00037     serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
00038 
00039     portFound = 0;
00040     while (portFound != 1 and currentPort < 65536):
00041         try :
00042             serversocket.bind((socket.gethostname(), currentPort));
00043             portFound = 1;
00044             print str(currentPort) + ": " + "OK";
00045 #            serversocket.shutdown(0);
00046 #            serversocket.close();
00047         except Exception, inst:
00048             print str(currentPort) + ": " + str(inst.args);
00049             currentPort = currentPort+step;
00050     
00051     
00052     
00053     
00054     if (portFound != 1) :
00055         currentPort = -1;
00056     return currentPort;
00057 #####################################################################
00058 
00059 
00060 
00061 ## 1. Generate config file for omniORB:
00062 # content:
00063 # InitRef = NameService=corbaname::[HOST_NAME]:[PORT_NUMBER]
00064 
00065 freePort = findFreePort(2810, 1);
00066 hostName = socket.gethostname();
00067 
00068 if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
00069     print "port:" + str(freePort);
00070     sys.exit(0)
00071     
00072 
00073         
00074 
00075 if freePort < 0 :
00076     print
00077     print "Can't find a free port to launch omniNames"
00078     print "Try to kill the running servers and then launch SALOME again."
00079     print
00080     sys.exit(0)
00081     
00082 else :
00083     omniCfgFileContent = "InitRef = NameService=corbaname::" + str(hostName) + ":" + str(freePort);
00084     omniCfgFilePath = os.environ.get('HOME') + "/" + ".omniORB_" + str(hostName) + "_" + str(freePort) + ".cfg";
00085 
00086     omni_file = file(omniCfgFilePath,'w+');
00087     omni_file.write(omniCfgFileContent);
00088     omni_file.write("\n");
00089     omni_file.close();
00090 
00091     if (len(sys.argv) > 1) and sys.argv[1] == "--save-config" :
00092         omniCfgCurrent = os.environ.get('HOME') + "/.omniORB_current.cfg";
00093         if os.name == "posix" :
00094             #make a symbolic link
00095             symlink(omniCfgFilePath, omniCfgCurrent);
00096         else :
00097             #copy the file
00098             shutil.copy(omniCfgFilePath, omniCfgCurrent);
00099             
00100         omniCfgFilePath = omniCfgCurrent;
00101             
00102     
00103     
00104 
00105     ## 2. Set the OMNIORB_CONFIG environment variable
00106     os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
00107 
00108 
00109     ## 3. execute the file runSalome.py
00110     runSalomePyFilePath = os.environ.get('KERNEL_ROOT_DIR') + "/bin/salome/runSalome.py";
00111 
00112     if os.path.isfile(runSalomePyFilePath) :
00113         execfile(runSalomePyFilePath);
00114