2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
30 #####################################################################
31 def findFreePort(startPort, step) :
33 currentPort = startPort;
37 serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
40 while (portFound != 1 and currentPort < 65536):
42 serversocket.bind((socket.gethostname(), currentPort));
44 print str(currentPort) + ": " + "OK";
45 # serversocket.shutdown(0);
46 # serversocket.close();
47 except Exception, inst:
48 print str(currentPort) + ": " + str(inst.args);
49 currentPort = currentPort+step;
57 #####################################################################
61 ## 1. Generate config file for omniORB:
63 # InitRef = NameService=corbaname::[HOST_NAME]:[PORT_NUMBER]
65 freePort = findFreePort(2810, 1);
66 hostName = socket.gethostname();
68 if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
69 print "port:" + str(freePort);
77 print "Can't find a free port to launch omniNames"
78 print "Try to kill the running servers and then launch SALOME again."
83 omniCfgFileContent = "InitRef = NameService=corbaname::" + str(hostName) + ":" + str(freePort);
84 omniCfgFilePath = os.environ.get('HOME') + "/" + ".omniORB_" + str(hostName) + "_" + str(freePort) + ".cfg";
86 omni_file = file(omniCfgFilePath,'w+');
87 omni_file.write(omniCfgFileContent);
88 omni_file.write("\n");
91 if (len(sys.argv) > 1) and sys.argv[1] == "--save-config" :
92 omniCfgCurrent = os.environ.get('HOME') + "/.omniORB_current.cfg";
93 if os.name == "posix" :
95 symlink(omniCfgFilePath, omniCfgCurrent);
98 shutil.copy(omniCfgFilePath, omniCfgCurrent);
100 omniCfgFilePath = omniCfgCurrent;
105 ## 2. Set the OMNIORB_CONFIG environment variable
106 os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
109 ## 3. execute the file runSalome.py
110 runSalomePyFilePath = os.environ.get('KERNEL_ROOT_DIR') + "/bin/salome/runSalome.py";
112 if os.path.isfile(runSalomePyFilePath) :
113 execfile(runSalomePyFilePath);