-def searchFreePort(args, save_config=1):
- print "Searching for a free port for naming service:",
- NSPORT=2810
- limit=NSPORT
- limit=limit+10
- while 1:
- import os
- import re
- from os import getpid
- from os import system
-
- if sys.platform == "win32":
- tmp_file = os.getenv('TEMP');
- else:
- tmp_file = '/tmp/'
- tmp_file += 'hostname_%s'%(getpid())
-
-# status = os.system("netstat -ltn | grep -E :%s > /dev/null 2>&1"%(NSPORT))
-
- system( "netstat -a -n > %s" % tmp_file );
-
- f = open( tmp_file, 'r' );
- lines = f.readlines();
- f.close();
-
- pattern = "tcp.*:([0-9]+).*:.*listen";
- regObj = re.compile( pattern, re.IGNORECASE );
-
- status = 1;
- for item in lines:
- m = regObj.search( item )
- if m:
- try:
- p = int( m.group(1) )
- if p == NSPORT:
- status = 0;
- break;
- except:
- pass
- pass
-
- if status == 1:
- print "%s - OK"%(NSPORT)
- #
- system('hostname > %s'%(tmp_file))
- f = open(tmp_file)
- myhost = f.read()
- myhost = myhost[:-1]
- f.close()
-
- os.remove( tmp_file );
-
- #
- home = os.environ['HOME']
- appli=os.environ.get("APPLI")
- if appli is not None:
- home='%s/%s'%(home,appli)
- pass
- #
- os.environ['OMNIORB_CONFIG'] = '%s/.omniORB_%s_%s.cfg'%(home, myhost, NSPORT)
- initref = "NameService=corbaname::%s:%s"%(myhost, NSPORT)
- os.environ['NSPORT'] = "%s"%(NSPORT)
- os.environ['NSHOST'] = "%s"%(myhost)
- f = open(os.environ['OMNIORB_CONFIG'], "w")
- import CORBA
- if CORBA.ORB_ID == "omniORB4":
- initref += "\ngiopMaxMsgSize = 2097152000 # 2 GBytes";
- initref += "\ntraceLevel = 0 # critical errors only";
- f.write("InitRef = %s\n"%(initref))
- else:
- initref += "\nORBgiopMaxMsgSize = 2097152000 # 2 GBytes";
- initref += "\nORBtraceLevel = 0 # critical errors only";
- f.write("ORBInitRef %s\n"%(initref))
- pass
- f.close()
- args['port'] = os.environ['NSPORT']
- #
- if save_config:
- from os import system
- if sys.platform == "win32":
- import shutil
- shutil.copyfile( os.environ['OMNIORB_CONFIG'], "%s/.omniORB_last.cfg"%( home ) )
- else:
- system('ln -s -f %s %s/.omniORB_last.cfg'%(os.environ['OMNIORB_CONFIG'], home))
- pass
- break
- print "%s"%(NSPORT),
- if NSPORT == limit:
- msg = "\n"
- msg += "Can't find a free port to launch omniNames\n"
- msg += "Try to kill the running servers and then launch SALOME again.\n"
- raise msg
- NSPORT=NSPORT+1
- pass
- return
-
-# -----------------------------------------------------------------------------
-