Salome HOME
Improve SALOME logger: customize log file name (add port, user and host ids) to avoid...
[modules/kernel.git] / bin / launchSalome.py
1 #!/usr/bin/env python
2
3 import socket
4 import os
5 import sys
6 import shutil
7
8 #####################################################################
9 def findFreePort(startPort, step) :
10
11     currentPort = startPort;
12     if step < 1:
13         step = 1;
14
15     serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
16
17     portFound = 0;
18     while (portFound != 1 and currentPort < 65536):
19         try :
20             serversocket.bind((socket.gethostname(), currentPort));
21             portFound = 1;
22             print str(currentPort) + ": " + "OK";
23 #            serversocket.shutdown(0);
24 #            serversocket.close();
25         except Exception, inst:
26             print str(currentPort) + ": " + str(inst.args);
27             currentPort = currentPort+step;
28     
29     
30     
31     
32     if (portFound != 1) :
33         currentPort = -1;
34     return currentPort;
35 #####################################################################
36
37
38
39 ## 1. Generate config file for omniORB:
40 # content:
41 # InitRef = NameService=corbaname::[HOST_NAME]:[PORT_NUMBER]
42
43 freePort = findFreePort(2810, 1);
44 hostName = socket.gethostname();
45
46 if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
47     print "port:" + str(freePort);
48     sys.exit(0)
49     
50
51         
52
53 if freePort < 0 :
54     print
55     print "Can't find a free port to launch omniNames"
56     print "Try to kill the running servers and then launch SALOME again."
57     print
58     sys.exit(0)
59     
60 else :
61     omniCfgFileContent = "InitRef = NameService=corbaname::" + str(hostName) + ":" + str(freePort);
62     omniCfgFilePath = os.environ.get('HOME') + "/" + ".omniORB_" + str(hostName) + "_" + str(freePort) + ".cfg";
63
64     omni_file = file(omniCfgFilePath,'w+');
65     omni_file.write(omniCfgFileContent);
66     omni_file.write("\n");
67     omni_file.close();
68
69     if (len(sys.argv) > 1) and sys.argv[1] == "--save-config" :
70         omniCfgCurrent = os.environ.get('HOME') + "/.omniORB_current.cfg";
71         if os.name == "posix" :
72             #make a symbolic link
73             symlink(omniCfgFilePath, omniCfgCurrent);
74         else :
75             #copy the file
76             shutil.copy(omniCfgFilePath, omniCfgCurrent);
77             
78         omniCfgFilePath = omniCfgCurrent;
79             
80     
81     
82
83     ## 2. Set the OMNIORB_CONFIG environment variable
84     os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
85
86
87     ## 3. execute the file runSalome.py
88     runSalomePyFilePath = os.environ.get('KERNEL_ROOT_DIR') + "/bin/salome/runSalome.py";
89
90     if os.path.isfile(runSalomePyFilePath) :
91         execfile(runSalomePyFilePath);
92