]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Improvement PAL13956: improve runSalome script: apply patch from Erwan ADAM
authorvsr <vsr@opencascade.com>
Tue, 21 Nov 2006 11:10:27 +0000 (11:10 +0000)
committervsr <vsr@opencascade.com>
Tue, 21 Nov 2006 11:10:27 +0000 (11:10 +0000)
bin/runSalome
bin/runSalome.py

index cf715b617d28285412397aa947f500e883d084d3..a898c8df32eacdf92ac46e4ecfe7001a8dbc3ce7 100755 (executable)
@@ -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
index f26ef6a4c2cd07faddbd00f2fd26b3053c56a6f1..7c02ebbf492f615e4f77d76ac2a3c8b70f884e1c 100755 (executable)
@@ -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