From dd040400d9d11eee2098650a2280ab9e6950d687 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 21 Nov 2006 11:10:27 +0000 Subject: [PATCH] Improvement PAL13956: improve runSalome script: apply patch from Erwan ADAM --- bin/runSalome | 44 +--------------------------- bin/runSalome.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 43 deletions(-) diff --git a/bin/runSalome b/bin/runSalome index cf715b617..a898c8df3 100755 --- a/bin/runSalome +++ b/bin/runSalome @@ -1,48 +1,6 @@ #!/bin/bash -save_config=$1 - -searchFreePort() { - echo -n "Searching for a free port for naming service: " - export NSPORT=2810 - local limit=$NSPORT - let limit=limit+100 - while [ 1 ] - do - aRes=`netstat -ltn | grep -E :${NSPORT}` - if [ -z "$aRes" ]; then - echo ${NSPORT} - Ok - local myhost=`hostname` - export OMNIORB_CONFIG=${HOME}/.omniORB_${myhost}_${NSPORT}.cfg - local initref="NameService=corbaname::"`hostname`":$NSPORT" - export NSPORT - if [[ `python -c "import CORBA; print CORBA.ORB_ID"` == "omniORB4" ]]; then - echo "InitRef = $initref" > $OMNIORB_CONFIG - else - echo "ORBInitRef $initref" > $OMNIORB_CONFIG - fi - if [[ "$save_config" == "--save-config" ]] ; then - ln -sf $OMNIORB_CONFIG ${HOME}/.omniORB_current.cfg - export OMNIORB_CONFIG=${HOME}/.omniORB_current.cfg - fi - break - fi - echo -n "${NSPORT} " - if [[ $NSPORT -eq $limit ]] ; then - echo - echo "Can't find a free port to launch omniNames" - echo "Try to kill the running servers and then launch SALOME again." - exit - fi - let NSPORT=NSPORT+1 - done -} - -searchFreePort - -if [[ "$*" == "-nothing" ]]; then - echo "port:$NSPORT" -elif [ $# -ne 0 ] ; then +if [ $# -ne 0 ] ; then python -i ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $* else python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py diff --git a/bin/runSalome.py b/bin/runSalome.py index f26ef6a4c..7c02ebbf4 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -856,6 +856,59 @@ def registerEnv(args, modules_list, modules_root_dir): # ----------------------------------------------------------------------------- +def searchFreePort(save_config=0): + print "Searching for a free port for naming service:", + NSPORT=2810 + limit=NSPORT + limit=limit+10 + while 1: + import os + status = os.system("netstat -ltn | grep -E :%s > /dev/null 2>&1"%(NSPORT)) + if status: + print "%s - OK"%(NSPORT) + # + from os import getpid + tmp_file = '/tmp/hostname_%s'%(getpid()) + from os import system + system('hostname > %s'%(tmp_file)) + f = open(tmp_file) + myhost = f.read() + myhost = myhost[:-1] + f.close() + system('rm -f %s'%(tmp_file)) + # + home = os.environ['HOME'] + # + os.environ['OMNIORB_CONFIG'] = '%s/.omniORB_%s_%s.cfg'%(home, myhost, NSPORT) + initref = "NameService=corbaname::%s:%s"%(myhost, NSPORT) + os.environ['NSPORT'] = "%s"%(NSPORT) + f = open(os.environ['OMNIORB_CONFIG'], "w") + import CORBA + if CORBA.ORB_ID == "omniORB4": + f.write("InitRef = %s\n"%(initref)) + else: + f.write("ORBInitRef %s\n"%(initref)) + pass + f.close() + # + if save_config: + from os import system + system('ln -sf %s %s/.omniORB_current.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 + +# ----------------------------------------------------------------------------- + def no_main(): """Salome Launch, when embedded in other application""" fileEnv = os.environ["SALOME_LAUNCH_CONFIG"] @@ -863,6 +916,7 @@ def no_main(): args, modules_list, modules_root_dir = pickle.load(fenv) fenv.close() kill_salome(args) + searchFreePort(0) clt = useSalome(args, modules_list, modules_root_dir) return clt @@ -870,8 +924,28 @@ def no_main(): def main(): """Salome launch as a main application""" + import sys + if len(sys.argv) == 2: + if sys.argv[1] == "-nothing": + searchFreePort() + import os + print "port:%s"%(os.environ['NSPORT']) + import sys + sys.exit(0) + pass + pass + save_config = 0 + import sys + if len(sys.argv) > 1: + if sys.argv[1] == "--save-config": + save_config = 1 + sys.argv[1:2] = [] + pass + pass + # args, modules_list, modules_root_dir = get_config() kill_salome(args) + searchFreePort(save_config) set_env(args, modules_list, modules_root_dir) clt = useSalome(args, modules_list, modules_root_dir) return clt,args -- 2.39.2