Salome HOME
Add missing include directory for CMake compilation.
[modules/kernel.git] / bin / launchSalome.py
1 #! /usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
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.
12 #
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.
17 #
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
21 #
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24
25 import socket
26 import os
27 import sys
28 import shutil
29
30 #####################################################################
31 def findFreePort(startPort, step) :
32
33     currentPort = startPort;
34     if step < 1:
35         step = 1;
36
37     serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
38
39     portFound = 0;
40     while (portFound != 1 and currentPort < 65536):
41         try :
42             serversocket.bind((socket.gethostname(), currentPort));
43             portFound = 1;
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;
50
51
52
53
54     if (portFound != 1) :
55         currentPort = -1;
56     return currentPort;
57 #####################################################################
58
59
60
61 ## 1. Generate config file for omniORB:
62 # content:
63 # InitRef = NameService=corbaname::[HOST_NAME]:[PORT_NUMBER]
64
65 freePort = findFreePort(2810, 1);
66 hostName = socket.gethostname();
67
68 if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
69     print "port:" + str(freePort);
70     sys.exit(0)
71
72 if freePort < 0 :
73     print
74     print "Can't find a free port to launch omniNames"
75     print "Try to kill the running servers and then launch SALOME again."
76     print
77     sys.exit(0)
78
79 else :
80     from ORBConfigFile import writeORBConfigFile
81     writeORBConfigFile(os.environ.get('HOME'), hostName, freePort)
82
83     if (len(sys.argv) > 1) and sys.argv[1] == "--save-config" :
84         omniCfgCurrent = os.environ.get('HOME') + "/.omniORB_current.cfg";
85         if os.name == "posix" :
86             #make a symbolic link
87             symlink(omniCfgFilePath, omniCfgCurrent);
88         else :
89             #copy the file
90             shutil.copy(omniCfgFilePath, omniCfgCurrent);
91
92         omniCfgFilePath = omniCfgCurrent;
93
94
95     ## 2. Set the OMNIORB_CONFIG environment variable
96     os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
97
98
99     ## 3. execute the file runSalome.py
100     runSalomePyFilePath = os.environ.get('KERNEL_ROOT_DIR') + "/bin/salome/runSalome.py";
101
102     if os.path.isfile(runSalomePyFilePath) :
103         execfile(runSalomePyFilePath);