8 #####################################################################
9 def findFreePort(startPort, step) :
11 currentPort = startPort;
15 serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
18 while (portFound != 1 and currentPort < 65536):
20 serversocket.bind((socket.gethostname(), currentPort));
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;
35 #####################################################################
39 ## 1. Generate config file for omniORB:
41 # InitRef = NameService=corbaname::[HOST_NAME]:[PORT_NUMBER]
43 freePort = findFreePort(2810, 1);
44 hostName = socket.gethostname();
46 if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
47 print "port:" + str(freePort);
55 print "Can't find a free port to launch omniNames"
56 print "Try to kill the running servers and then launch SALOME again."
61 omniCfgFileContent = "InitRef = NameService=corbaname::" + str(hostName) + ":" + str(freePort);
62 omniCfgFilePath = os.environ.get('HOME') + "/" + ".omniORB_" + str(hostName) + "_" + str(freePort) + ".cfg";
64 omni_file = file(omniCfgFilePath,'w+');
65 omni_file.write(omniCfgFileContent);
66 omni_file.write("\n");
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" :
73 symlink(omniCfgFilePath, omniCfgCurrent);
76 shutil.copy(omniCfgFilePath, omniCfgCurrent);
78 omniCfgFilePath = omniCfgCurrent;
83 ## 2. Set the OMNIORB_CONFIG environment variable
84 os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
87 ## 3. execute the file runSalome.py
88 runSalomePyFilePath = os.environ.get('KERNEL_ROOT_DIR') + "/bin/salome/runSalome.py";
90 if os.path.isfile(runSalomePyFilePath) :
91 execfile(runSalomePyFilePath);