2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
28 #####################################################################
29 def findFreePort(startPort, step) :
31 currentPort = startPort;
35 serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
38 while (portFound != 1 and currentPort < 65536):
40 serversocket.bind((socket.gethostname(), currentPort));
42 print str(currentPort) + ": " + "OK";
43 # serversocket.shutdown(0);
44 # serversocket.close();
45 except Exception, inst:
46 print str(currentPort) + ": " + str(inst.args);
47 currentPort = currentPort+step;
55 #####################################################################
59 ## 1. Generate config file for omniORB:
61 # InitRef = NameService=corbaname::[HOST_NAME]:[PORT_NUMBER]
63 freePort = findFreePort(2810, 1);
64 hostName = socket.gethostname();
66 if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
67 print "port:" + str(freePort);
75 print "Can't find a free port to launch omniNames"
76 print "Try to kill the running servers and then launch SALOME again."
81 omniCfgFileContent = "InitRef = NameService=corbaname::" + str(hostName) + ":" + str(freePort);
82 omniCfgFilePath = os.environ.get('HOME') + "/" + ".omniORB_" + str(hostName) + "_" + str(freePort) + ".cfg";
84 omni_file = file(omniCfgFilePath,'w+');
85 omni_file.write(omniCfgFileContent);
86 omni_file.write("\n");
89 if (len(sys.argv) > 1) and sys.argv[1] == "--save-config" :
90 omniCfgCurrent = os.environ.get('HOME') + "/.omniORB_current.cfg";
91 if os.name == "posix" :
93 symlink(omniCfgFilePath, omniCfgCurrent);
96 shutil.copy(omniCfgFilePath, omniCfgCurrent);
98 omniCfgFilePath = omniCfgCurrent;
103 ## 2. Set the OMNIORB_CONFIG environment variable
104 os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
107 ## 3. execute the file runSalome.py
108 runSalomePyFilePath = os.environ.get('KERNEL_ROOT_DIR') + "/bin/salome/runSalome.py";
110 if os.path.isfile(runSalomePyFilePath) :
111 execfile(runSalomePyFilePath);