From: aguerre Date: Mon, 22 Oct 2012 14:37:14 +0000 (+0000) Subject: CA: Bug correction PAL2416 X-Git-Tag: B4NGCMakeInt~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=abaae579d74155ea9ef440bc4e0c6b09450aa1a2;p=modules%2Fkernel.git CA: Bug correction PAL2416 CORBA configuration for GIOP Max msg size (set to 2GB). Done in only one place. M bin/CMakeLists.txt M bin/Makefile.am A bin/ORBConfigFile.py M bin/killSalome.py M bin/killSalomeWithPort.py M bin/launchConfigureParser.py M bin/launchSalome.py M bin/orbmodule.py M bin/runSalome.ksh M bin/runSalome.py M bin/salomeConsole.py M bin/salome_session.py A bin/searchFreePort.py M bin/appliskel/runRemote.sh M bin/appliskel/runSession M bin/appliskel/runTests M bin/appliskel/searchFreePort.sh --- diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 2f4536803..61db93c62 100755 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -52,11 +52,13 @@ SET(SCRIPTS nameserver.py NSparam.py orbmodule.py + ORBConfigFile.py runNS.py runSalome.py salomeConsole.py salome_session.py salome_utils.py + searchFreePort.py server.py setenv.py showNS.py diff --git a/bin/Makefile.am b/bin/Makefile.am index 039f9b468..b50c28136 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -20,7 +20,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# -* Makefile *- +# -* Makefile *- # Author : Guillaume Boulant (CSSI) # Module : KERNEL # $Header$ @@ -68,11 +68,13 @@ dist_salomescript_PYTHON = \ nameserver.py \ NSparam.py \ orbmodule.py \ + ORBConfigFile.py \ runNS.py \ runSalome.py \ salomeConsole.py \ salome_session.py \ - salome_utils.py \ + salome_utils.py \ + searchFreePort.py \ server.py \ setenv.py \ showNS.py \ @@ -83,5 +85,5 @@ dist_salomescript_PYTHON = \ install-data-hook: @for f in $(dist_salomescript_PYTHON) ; do \ - chmod -f a+x $(DESTDIR)$(salomescriptdir)/$$f ; \ - done + chmod -f a+x $(DESTDIR)$(salomescriptdir)/$$f ; \ + done diff --git a/bin/ORBConfigFile.py b/bin/ORBConfigFile.py new file mode 100644 index 000000000..58b6c208e --- /dev/null +++ b/bin/ORBConfigFile.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# IMPORTANT NOTE: do not add any print call (cf. note at the bottom of the file) +def writeORBConfigFile(path, host, port, kwargs={}): + + from salome_utils import generateFileName + omniorb_config = generateFileName(path, prefix="omniORB", + extension="cfg", + hidden=True, + with_hostname=True, + with_port=port, + **kwargs) + import os + os.environ['OMNIORB_CONFIG'] = omniorb_config + os.environ['NSPORT'] = "%s"%(port) + os.environ['NSHOST'] = "%s"%(host) + + from omniORB import CORBA + prefix = "" if CORBA.ORB_ID == "omniORB4" else "ORB" + + GIOP_MaxMsgSize=2097152000 # 2 GBytes + + orbdata = [] + orbdata.append("%sInitRef = NameService=corbaname::%s:%s"%(prefix,host,port)) + orbdata.append("%sgiopMaxMsgSize = %s # 2 GBytes"%(prefix,GIOP_MaxMsgSize)) + orbdata.append("%straceLevel = 0 # critical errors only"%(prefix)) + orbdata.append("") + + f = open(omniorb_config, "w") + f.write("\n".join(orbdata)) + f.close() + + return [ omniorb_config, GIOP_MaxMsgSize ] + +# ----------------------------------------------------------------------------- + +if __name__ == "__main__": + import sys, getopt + + path = sys.argv[1] + host = sys.argv[2] + port = sys.argv[3] + argv = sys.argv[4:] + + kwargs = {} + for a in argv: + alist = str(a).split("=", 1) + opt = str(alist[0]) + arg = alist[1] + kwargs[opt] = arg + pass + + [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs) + + # :TRICKY: print values so they can be read from caller bash script + # Example of bash script: + # RETURN_VALUES=$(python ORBConfigFile.py path host port) + # RETURN_VALUE_1=$(echo ${RETURN_VALUES} | cut -d' ' -f1) + # RETURN_VALUE_2=$(echo ${RETURN_VALUES} | cut -d' ' -f2) + # ... + # IMPORTANT NOTE: this print call MUST BE the first one!! + print filename, msgSize diff --git a/bin/appliskel/runRemote.sh b/bin/appliskel/runRemote.sh index dead646a7..717085068 100755 --- a/bin/appliskel/runRemote.sh +++ b/bin/appliskel/runRemote.sh @@ -50,15 +50,12 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py` . ${HOME}/${APPLI}/envd ${HOME}/${APPLI} # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME +export NSHOST=$1 +export NSPORT=$2 -OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_$1_$2.cfg -export OMNIORB_CONFIG -NSHOST=$1 -export NSHOST -NSPORT=$2 -export NSPORT -initref="NameService=corbaname::"$1":$2" -echo "InitRef = $initref" > $OMNIORB_CONFIG +# Get (in bash) the configuration filename from (Python) ORBConfigFile return values +RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${HOME}/${APPLI}/USERS ${NSHOST} ${NSPORT} with_username=${USER}) +export OMNIORB_CONFIG=$(echo ${RETURN_VALUES} | cut -d' ' -f1) #go to the requested working directory if any if test "x$3" == "xWORKINGDIR"; then diff --git a/bin/appliskel/runSession b/bin/appliskel/runSession index f12e53c21..e1616f18b 100755 --- a/bin/appliskel/runSession +++ b/bin/appliskel/runSession @@ -68,6 +68,23 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py` . ${HOME}/${APPLI}/envd ${HOME}/${APPLI} +# --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME +# Usage: writeConfigFile PORT HOST +function writeConfigFile +{ + if [ $# -ne 2 ]; then + echo "Usage: $0 PORT HOST" + return + fi + export NSPORT=$1 + export NSHOST=$2 + + # Get (in bash) the configuration filename from (Python) ORBConfigFile return values + RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${HOME}/${APPLI}/USERS ${NSHOST} ${NSPORT} with_username=${USER}) + export OMNIORB_CONFIG=$(echo ${RETURN_VALUES} | cut -d' ' -f1) +} + + if test "x${NSPORT}" == "xlast"; then #PORT is not given if test "x${NSHOST}" == "xlocalhost"; then @@ -75,47 +92,28 @@ if test "x${NSPORT}" == "xlast"; then # --- set omniORB configuration to current session if any fileOmniConfig=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg if [ -f $fileOmniConfig ]; then - OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg - export OMNIORB_CONFIG + export OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg # --- set environment variables for port and hostname of NamingService - NSHOST=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py host` - NSPORT=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port` - export NSPORT - export NSHOST + export NSHOST=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py host` + export NSPORT=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port` fi else #MACHINE is given PORT is not given - NSPORT=2810 - OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${NSHOST}_${NSPORT}.cfg - export OMNIORB_CONFIG - #if omniorb config file exists do not override (perhaps too conservative) - if [ ! -f ${OMNIORB_CONFIG} ]; then - echo "InitRef = NameService=corbaname::${NSHOST}:${NSPORT}" > ${OMNIORB_CONFIG} - fi - export NSPORT - export NSHOST + writeConfigFile 2810 ${NSHOST} fi else #PORT is given if test "x${NSHOST}" == "xlocalhost"; then #MACHINE is not given PORT is given - NSHOST=`hostname` + NSHOST=`hostname` fi - OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${NSHOST}_${NSPORT}.cfg - export OMNIORB_CONFIG - #if omniorb config file exists do not override (perhaps too conservative) - if [ ! -f ${OMNIORB_CONFIG} ]; then - echo "InitRef = NameService=corbaname::${NSHOST}:${NSPORT}" > ${OMNIORB_CONFIG} - fi - export NSPORT - export NSHOST + writeConfigFile ${NSPORT} ${NSHOST} fi # --- invoke shell with or without args if [ $# -ne 0 ] ; then - ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py -exec $* + ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py -exec $* else - - ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/bash --rcfile ${HOME}/${APPLI}/.bashrc + ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/bash --rcfile ${HOME}/${APPLI}/.bashrc fi diff --git a/bin/appliskel/runTests b/bin/appliskel/runTests index 352daad91..f7f9ad98c 100755 --- a/bin/appliskel/runTests +++ b/bin/appliskel/runTests @@ -30,44 +30,6 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py` . ${HOME}/${APPLI}/envd ${HOME}/${APPLI} -# --- define port for CORBA naming service - -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` - OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${myhost}_${NSPORT}.cfg - export OMNIORB_CONFIG - export NSPORT - NSHOST=${myhost} - export NSHOST - local initref="NameService=corbaname::"`hostname`":$NSPORT" - #echo "ORBInitRef $initref" > $OMNIORB_CONFIG - echo "InitRef = $initref" > $OMNIORB_CONFIG - LAST_RUNNING_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${myhost}_test.cfg - export LAST_RUNNING_CONFIG - rm ${LAST_RUNNING_CONFIG} - ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG} - 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 -} - # --- if mpi lam, start lam (seems safe to be done several times) # arret manuel avec lamhalt @@ -77,7 +39,7 @@ fi # --- invoque shell with or without args -searchFreePort +searchFreePort save test if [ $# -ne 0 ] ; then ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/bash --rcfile ${HOME}/${APPLI}/.bashrc -c "$*" diff --git a/bin/appliskel/searchFreePort.sh b/bin/appliskel/searchFreePort.sh index 8d0346561..bda749fc7 100755 --- a/bin/appliskel/searchFreePort.sh +++ b/bin/appliskel/searchFreePort.sh @@ -23,30 +23,44 @@ # --- define port for CORBA naming service +DEFAULT=default + +# call: searchFreePort [ save [test] ] searchFreePort() { + # if not specified by optional first parameter, savemode is set to default + savemode=${1:-$DEFAULT} + # if not specified by optional second parameter, testmode is set to default + testmode=${2:-$DEFAULT} + echo -n "Searching for a free port for naming service: " - NSPORT=2810 - export NSPORT + 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` - OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${myhost}_${NSPORT}.cfg - export OMNIORB_CONFIG - export NSPORT - NSHOST=${myhost} - export NSHOST - local initref="NameService=corbaname::"`hostname`":$NSPORT" - #echo "ORBInitRef $initref" > $OMNIORB_CONFIG - echo "InitRef = $initref" > $OMNIORB_CONFIG - LAST_RUNNING_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg - export LAST_RUNNING_CONFIG - rm ${LAST_RUNNING_CONFIG} - ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG} + export NSPORT + export NSHOST=`hostname` + + RETURN_VALUES=$(${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/ORBConfigFile.py ${HOME}/${APPLI}/USERS ${NSHOST} ${NSPORT} with_username=${USER}) + export OMNIORB_CONFIG=$(echo ${RETURN_VALUES} | cut -d' ' -f1) + + if [ "$savemode" = save ] + then + if [ "$testmode" = test ] + then + export LAST_RUNNING_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${NSHOST}_test.cfg + else + export LAST_RUNNING_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg + fi + + rm ${LAST_RUNNING_CONFIG} + ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG} + fi + break fi echo -n "${NSPORT} " @@ -59,4 +73,3 @@ searchFreePort() { let NSPORT=NSPORT+1 done } - diff --git a/bin/killSalome.py b/bin/killSalome.py index 020f7ed44..26dc0bb6f 100755 --- a/bin/killSalome.py +++ b/bin/killSalome.py @@ -96,4 +96,3 @@ def killAllPorts(): if __name__ == "__main__": killAllPorts() pass - diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 57729aa88..705c8e3ca 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -117,7 +117,7 @@ def appliCleanOmniOrbConfig(port): os.remove(omniorb_config) pass - if os.path.lexists(last_running_config):return + if os.path.lexists(last_running_config):return #try to relink last.cfg to an existing config file if any files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(), @@ -144,14 +144,14 @@ def shutdownMyPort(port): - port - port number """ if not port: return - + from salome_utils import generateFileName # set OMNIORB_CONFIG variable to the proper file home = os.getenv("HOME") appli = os.getenv("APPLI") kwargs = {} - if appli is not None: + if appli is not None: home = os.path.join(os.path.realpath(home), appli,"USERS") kwargs["with_username"]=True pass @@ -177,7 +177,7 @@ def shutdownMyPort(port): except: pass pass - + def killMyPort(port): """ Kill SALOME session running on the specified port. @@ -185,12 +185,12 @@ def killMyPort(port): - port - port number """ from salome_utils import getShortHostName, getHostName - + # try to shutdown session nomally import threading, time threading.Thread(target=shutdownMyPort, args=(port,)).start() time.sleep(3) # wait a little, then kill processes (should be done if shutdown procedure hangs up) - + # new-style dot-prefixed pidict file filedict = getPiDict(port, hidden=True) # provide compatibility with old-style pidict file (not dot-prefixed) @@ -218,7 +218,7 @@ def killMyPort(port): suffix="Pid_omniNames", extension="log", with_port=port) - if not sys.platform == 'win32': + if not sys.platform == 'win32': cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start %s"` ; echo $pid > %s' % ( str(port), fpidomniNames ) a = os.system(cmd) pass @@ -255,7 +255,7 @@ def killMyPort(port): try: if sys.platform == "win32": import win32pm - win32pm.killpid(int(pid),0) + win32pm.killpid(int(pid),0) else: os.kill(int(pid),signal.SIGKILL) pass @@ -285,7 +285,7 @@ def killMyPort(port): # appliCleanOmniOrbConfig(port) pass - + def killNotifdAndClean(port): """ Kill notifd daemon and clean application running on the specified port. diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 1bb30d33a..92b5e9aea 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -173,11 +173,11 @@ def userFile(appname, cfgname): # get app version v = version() if not v: return None # unknown version - + # get default user file name filename = defaultUserFile(appname, cfgname) if not filename: return None # default user file name is bad - + # check that default user file exists if os.path.exists(filename): return filename # user file is found @@ -186,7 +186,7 @@ def userFile(appname, cfgname): # ... calculate default version id id0 = version_id(v) if not id0: return None # bad version id -> can't detect appropriate file - + # ... get all existing user preferences files if sys.platform == "win32": files = glob.glob(os.path.join(getHomeDir(), "%s.xml.*" % appname)) @@ -301,11 +301,11 @@ class xml_parser: def startElement(self, name, attrs): self.space.append(name) self.current = None - + # if we are importing file if self.space == [doc_tag, import_tag] and nam_att in attrs.getNames(): self.importFile( attrs.getValue(nam_att) ) - + # if we are analyzing "section" element and its "name" attribute is # either "launch" or module name -- set section_name if self.space == [doc_tag, sec_tag] and nam_att in attrs.getNames(): @@ -366,14 +366,14 @@ class xml_parser: def endDocument(self): self.read = None pass - + def importFile(self, fname): # get absolute name if os.path.isabs (fname) : absfname = fname else: absfname = os.path.join(os.path.dirname(self.fileName), fname) - + # check existing and registry file for ext in ["", ".xml", ".XML"] : if os.path.exists(absfname + ext) : @@ -386,7 +386,7 @@ class xml_parser: else: if verbose(): print "Configure parser: Error : file %s does not exist" % absfname return - + # importing file try: # copy current options @@ -404,7 +404,7 @@ class xml_parser: except: if verbose(): print "Configure parser: Error : can not read configuration file %s" % absfname pass - + # ----------------------------------------------------------------------------- @@ -876,7 +876,7 @@ def get_env(theAdditionalOptions=[], appname=salomeappname, cfgname=salomecfgnam # Process --print-port option if cmd_opts.print_port: - from runSalome import searchFreePort + from searchFreePort import searchFreePort searchFreePort({}) print "port:%s"%(os.environ['NSPORT']) sys.exit(0) diff --git a/bin/launchSalome.py b/bin/launchSalome.py index 9fe2af56b..0998452da 100755 --- a/bin/launchSalome.py +++ b/bin/launchSalome.py @@ -47,10 +47,10 @@ def findFreePort(startPort, step) : except Exception, inst: print str(currentPort) + ": " + str(inst.args); currentPort = currentPort+step; - - - - + + + + if (portFound != 1) : currentPort = -1; return currentPort; @@ -68,9 +68,6 @@ hostName = socket.gethostname(); if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" : print "port:" + str(freePort); sys.exit(0) - - - if freePort < 0 : print @@ -78,15 +75,10 @@ if freePort < 0 : print "Try to kill the running servers and then launch SALOME again." print sys.exit(0) - -else : - omniCfgFileContent = "InitRef = NameService=corbaname::" + str(hostName) + ":" + str(freePort); - omniCfgFilePath = os.environ.get('HOME') + "/" + ".omniORB_" + str(hostName) + "_" + str(freePort) + ".cfg"; - omni_file = file(omniCfgFilePath,'w+'); - omni_file.write(omniCfgFileContent); - omni_file.write("\n"); - omni_file.close(); +else : + from ORBConfigFile import writeORBConfigFile + writeORBConfigFile(os.environ.get('HOME'), hostName, freePort) if (len(sys.argv) > 1) and sys.argv[1] == "--save-config" : omniCfgCurrent = os.environ.get('HOME') + "/.omniORB_current.cfg"; @@ -96,11 +88,9 @@ else : else : #copy the file shutil.copy(omniCfgFilePath, omniCfgCurrent); - + omniCfgFilePath = omniCfgCurrent; - - - + ## 2. Set the OMNIORB_CONFIG environment variable os.environ['OMNIORB_CONFIG']=omniCfgFilePath; @@ -111,4 +101,3 @@ else : if os.path.isfile(runSalomePyFilePath) : execfile(runSalomePyFilePath); - diff --git a/bin/orbmodule.py b/bin/orbmodule.py index 0499db75b..507c68c39 100755 --- a/bin/orbmodule.py +++ b/bin/orbmodule.py @@ -41,10 +41,9 @@ class client: """Client for SALOME""" def __init__(self,args=None): - #set GIOP message size for bug 10560: impossible to get field values in TUI mode - sys.argv.extend(["-ORBgiopMaxMsgSize", "104857600"]) ## = 100 * 1024 * 1024 # Initialise the ORB self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + # Initialise the Naming Service self.initNS(args or {}) @@ -59,7 +58,7 @@ class client: except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE): self.rootContext = None if verbose(): print "Launch Naming Service++", - + # On lance le Naming Server (doit etre dans le PATH) test = True if args['wake_up_session']: @@ -142,14 +141,14 @@ class client: count += 1 if count > maxcount : raise RuntimeError, "Impossible de trouver %s" % name obj=self.Resolve(name) - if obj : + if obj : print " found in %s seconds " % ((count-1)*delta) break else: sys.stdout.write('+') sys.stdout.flush() time.sleep(delta) - + if typobj is None:return obj nobj = obj._narrow(typobj) @@ -170,7 +169,7 @@ class client: raise RuntimeError, "Process %d for %s not found" % (thePID,theName) aCount += 1 anObj = self.Resolve(theName) - if anObj: + if anObj: print " found in %s seconds " % ((aCount-1)*aDelta) break else: @@ -179,7 +178,7 @@ class client: time.sleep(aDelta) pass pass - + if theTypObj is None: return anObj @@ -206,7 +205,7 @@ class client: except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE): obj = None return obj - + # -------------------------------------------------------------------------- def waitLogger(self,name,typobj=None,maxcount=40): @@ -217,18 +216,17 @@ class client: count += 1 if count > maxcount : raise RuntimeError, "Impossible de trouver %s" % name obj=self.ResolveLogger(name) - if obj : + if obj : print " found in %s seconds " % ((count-1)*delta) break else: sys.stdout.write('+') sys.stdout.flush() time.sleep(delta) - + if typobj is None:return obj nobj = obj._narrow(typobj) if nobj is None: print "%s exists but is not a %s" % (name,typobj) return nobj - diff --git a/bin/runSalome.ksh b/bin/runSalome.ksh index 57804f295..2a02cf68d 100644 --- a/bin/runSalome.ksh +++ b/bin/runSalome.ksh @@ -21,46 +21,12 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -searchFreePort() { - echo -n "Searching for a free port for naming service: " - NSPORT=2810 - export NSPORT - 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` - OMNIORB_CONFIG=${HOME}/.omniORB_${myhost}_${NSPORT}.cfg - export OMNIORB_CONFIG - 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 - 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 - python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $* + python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $* else python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py fi @@ -73,7 +39,7 @@ fi # - parameters for launching are taken from SalomeApp.xml; # - if the config file does not exist, it is created with default values. # -# +# # $: ${KERNEL_ROOT_DIR}/bin/salome/runSalome --modules=GEOM,SMESH,VISU,MED --embedded=registry,study,moduleCatalog,cppContainer --standalone=pyContainer --xterm --killall # # parameters from command line supersede those from SalomeApp.xml @@ -92,7 +58,7 @@ fi # par defaut, les differents serveurs ouvrent des fenĂȘtres xterm # (cf. runSalome.py) # le serveur Logger n'est pas obligatoire (commentĂ© dans runSalome.py) -# +# # ----------------------------------------------------------------------------- # Example on CCRT (without ihm) : # ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py --terminal --modules=MED,CALCULATOR,COMPONENT --standalone=registry,study,moduleCatalog,cppContainer,pyContainer --killall diff --git a/bin/runSalome.py b/bin/runSalome.py index 7ced786fe..f6e76652f 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -46,7 +46,7 @@ def killLocalPort(): kill servers from a previous SALOME exection, if needed, on the CORBA port given in args of runSalome """ - + from killSalomeWithPort import killMyPort my_port=str(args['port']) try: @@ -55,13 +55,13 @@ def killLocalPort(): print "problem in killLocalPort()" pass pass - + def givenPortKill(port): """ kill servers from a previous SALOME exection, if needed, on the same CORBA port """ - + from killSalomeWithPort import killMyPort my_port=port try: @@ -96,7 +96,7 @@ class InterpServer(Server): self.CMD=['xterm', '-e']+ env_ld_library_path + ['python'] else: self.CMD=['cmd', '/c', 'start cmd.exe', '/K', 'python'] - + def run(self): global process_id command = self.CMD @@ -152,7 +152,7 @@ class CatalogServer(Server): self.SCMD2=[] home_dir=os.getenv('HOME') if home_dir is not None: - self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] + self.SCMD2=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] def setpath(self,modules_list,modules_root_dir): list_modules = modules_list[:] @@ -250,7 +250,7 @@ class SessionServer(Server): self.SCMD1+=['--with','ModuleCatalog','(','-common'] home_dir=os.getenv('HOME') if home_dir is not None: - self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] + self.SCMD2+=['-personal',os.path.join(home_dir,'Salome/resources/CatalogModulePersonnel.xml')] self.SCMD2+=[')'] if 'study' in self.args['embedded']: self.SCMD2+=['--with','SALOMEDS','(',')'] @@ -258,7 +258,7 @@ class SessionServer(Server): self.SCMD2+=['--with','Container','(','FactoryServer',')'] if 'SalomeAppEngine' in self.args['embedded']: self.SCMD2+=['--with','SalomeAppEngine','(',')'] - + if 'cppContainer' in self.args['standalone'] or 'cppContainer' in self.args['embedded']: self.SCMD2+=['CPP'] if 'pyContainer' in self.args['standalone'] or 'pyContainer' in self.args['embedded']: @@ -336,7 +336,7 @@ class SessionServer(Server): self.CMD = ["xterm", "-e", "gdb", "--command=.gdbinit4salome", self.CMD[0]] pass pass - + if self.args["valgrind_session"]: l = ["valgrind"] val = os.getenv("VALGRIND_OPTIONS") @@ -345,7 +345,7 @@ class SessionServer(Server): pass self.CMD = l + self.CMD pass - + # --- class LauncherServer(Server): @@ -409,7 +409,7 @@ def startGUI(clt): import SALOME_Session_idl session=clt.waitNS("/Kernel/Session",SALOME.Session) session.GetInterface() - + # ----------------------------------------------------------------------------- def startSalome(args, modules_list, modules_root_dir): @@ -417,13 +417,13 @@ def startSalome(args, modules_list, modules_root_dir): init_time = os.times() if verbose(): print "startSalome ", args - + # # Set server launch command # if args.has_key('server_launch_mode'): Server.set_server_launch_mode(args['server_launch_mode']) - + # # Wake up session option # @@ -433,7 +433,7 @@ def startSalome(args, modules_list, modules_root_dir): home = os.getenv("HOME") appli = os.getenv("APPLI") kwargs={} - if appli is not None: + if appli is not None: home = os.path.join(os.path.realpath(home), appli,"USERS") kwargs["with_username"] = True pass @@ -445,11 +445,11 @@ def startSalome(args, modules_list, modules_root_dir): os.environ['OMNIORB_CONFIG'] = last_running_config pass pass - + # # Initialisation ORB and Naming Service # - + clt=orbmodule.client(args) # @@ -481,7 +481,7 @@ def startSalome(args, modules_list, modules_root_dir): session.GetInterface() args["session_object"] = session return clt - + # Save Naming service port name into # the file args["ns_port_log_file"] if args.has_key('ns_port_log_file'): @@ -508,7 +508,7 @@ def startSalome(args, modules_list, modules_root_dir): if sys.platform != "win32": if verbose(): print "Notify Server to launch" - + myServer=NotifyServer(args,modules_root_dir) myServer.run() @@ -566,7 +566,7 @@ def startSalome(args, modules_list, modules_root_dir): # # Launch LauncherServer # - + myCmServer = LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() @@ -580,7 +580,7 @@ def startSalome(args, modules_list, modules_root_dir): from Utils_Identity import getShortHostName - + if os.getenv("HOSTNAME") == None: if os.getenv("HOST") == None: os.environ["HOSTNAME"]=getShortHostName() @@ -588,13 +588,13 @@ def startSalome(args, modules_list, modules_root_dir): os.environ["HOSTNAME"]=os.getenv("HOST") theComputer = getShortHostName() - + # # Launch local C++ Container (FactoryServer), # and wait until it is registered in naming service # - if ('cppContainer' in args['standalone']) | (args["gui"] == 0) : + if ('cppContainer' in args['standalone']) | (args["gui"] == 0) : myServer=ContainerCPPServer(args) myServer.run() if sys.platform == "win32": @@ -618,9 +618,9 @@ def startSalome(args, modules_list, modules_root_dir): # # Wait until Session Server is registered in naming service # - + if args["gui"]: -##---------------- +##---------------- import Engines import SALOME import SALOMEDS @@ -644,7 +644,7 @@ def startSalome(args, modules_list, modules_root_dir): # additionnal external python interpreters # nbaddi=0 - + try: if 'interp' in args: nbaddi = args['interp'] @@ -654,7 +654,7 @@ def startSalome(args, modules_list, modules_root_dir): print "-------------------------------------------------------------" print "-- to get an external python interpreter:runSalome --interp=1" print "-------------------------------------------------------------" - + if verbose(): print "additional external python interpreters: ", nbaddi if nbaddi: for i in range(nbaddi): @@ -669,7 +669,7 @@ def startSalome(args, modules_list, modules_root_dir): import readline except ImportError: pass - + return clt # ----------------------------------------------------------------------------- @@ -681,7 +681,7 @@ def useSalome(args, modules_list, modules_root_dir): show registered objects in Naming Service. """ global process_id - + clt=None try: clt = startSalome(args, modules_list, modules_root_dir) @@ -691,7 +691,7 @@ def useSalome(args, modules_list, modules_root_dir): print print print "--- Error during Salome launch ---" - + #print process_id from addToKillList import addToKillList @@ -705,28 +705,28 @@ def useSalome(args, modules_list, modules_root_dir): if verbose(): print """ Saving of the dictionary of Salome processes in %s To kill SALOME processes from a console (kill all sessions from all ports): - python killSalome.py + python killSalome.py To kill SALOME from the present interpreter, if it is not closed : killLocalPort() --> kill this session (use CORBA port from args of runSalome) - givenPortKill(port) --> kill a specific session with given CORBA port + givenPortKill(port) --> kill a specific session with given CORBA port killAllPorts() --> kill all sessions - + runSalome, with --killall option, starts with killing the processes resulting from the previous execution. """%filedict - + # # Print Naming Service directory list # - + if clt != None: if verbose(): print print " --- registered objects tree in Naming Service ---" clt.showNS() pass - + if not args['gui'] or not args['session_gui']: if args['shutdown_servers']: class __utils__(object): @@ -742,7 +742,7 @@ def useSalome(args, modules_list, modules_root_dir): args['shutdown_servers'] = __utils__(args['port']) pass pass - + # run python scripts, passed via --execute option toimport = [] if args.has_key('pyscript'): @@ -784,7 +784,7 @@ def useSalome(args, modules_list, modules_root_dir): pass pass return clt - + def execScript(script_path): print 'executing', script_path sys.path.insert(0, os.path.dirname(script_path)) @@ -812,112 +812,6 @@ def registerEnv(args, modules_list, modules_root_dir): # ----------------------------------------------------------------------------- -def searchFreePort(args, save_config=1): - print "Searching for a free port for naming service:", - # - if sys.platform == "win32": - tmp_file = os.getenv('TEMP'); - else: - tmp_file = '/tmp' - tmp_file = os.path.join(tmp_file, '.netstat_%s'%os.getpid()) - # - ###status = os.system("netstat -ltn | grep -E :%s > /dev/null 2>&1"%(NSPORT)) - os.system( "netstat -a -n > %s" % tmp_file ); - f = open( tmp_file, 'r' ); - ports = f.readlines(); - f.close(); - os.remove( tmp_file ); - # - def portIsUsed(port, data): - regObj = re.compile( ".*tcp.*:([0-9]+).*:.*listen", re.IGNORECASE ); - for item in data: - try: - p = int(regObj.match(item).group(1)) - if p == port: return True - pass - except: - pass - pass - return False - # - NSPORT=2810 - limit=NSPORT+100 - # - while 1: - if not portIsUsed(NSPORT, ports): - print "%s - OK"%(NSPORT) - # - from salome_utils import generateFileName, getHostName - hostname = getHostName() - # - home = os.getenv("HOME") - appli = os.getenv("APPLI") - kwargs={} - if appli is not None: - home = os.path.join(os.path.realpath(home), appli,"USERS") - kwargs["with_username"]=True - # - omniorb_config = generateFileName(home, prefix="omniORB", - extension="cfg", - hidden=True, - with_hostname=True, - with_port=NSPORT, - **kwargs) - orbdata = [] - initref = "NameService=corbaname::%s:%s"%(hostname, NSPORT) - from omniORB import CORBA - if CORBA.ORB_ID == "omniORB4": - orbdata.append("InitRef = %s"%(initref)) - orbdata.append("giopMaxMsgSize = 2097152000 # 2 GBytes") - orbdata.append("traceLevel = 0 # critical errors only") - else: - orbdata.append("ORBInitRef %s"%(initref)) - orbdata.append("ORBgiopMaxMsgSize = 2097152000 # 2 GBytes") - orbdata.append("ORBtraceLevel = 0 # critical errors only") - pass - orbdata.append("") - f = open(omniorb_config, "w") - f.write("\n".join(orbdata)) - f.close() - # - os.environ['OMNIORB_CONFIG'] = omniorb_config - os.environ['NSPORT'] = "%s"%(NSPORT) - os.environ['NSHOST'] = "%s"%(hostname) - args['port'] = os.environ['NSPORT'] - # - if save_config: - last_running_config = generateFileName(home, prefix="omniORB", - suffix="last", - extension="cfg", - hidden=True, - **kwargs) - try: - if sys.platform == "win32": - import shutil - shutil.copyfile(omniorb_config, last_running_config) - else: - try: - os.remove(last_running_config) - except OSError: - pass - os.symlink(omniorb_config, last_running_config) - pass - pass - except: - 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 RuntimeError, msg - NSPORT=NSPORT+1 - pass - return - -# ----------------------------------------------------------------------------- - def no_main(): """Salome Launch, when embedded in other application""" fileEnv = os.environ["SALOME_LAUNCH_CONFIG"] @@ -925,6 +819,7 @@ def no_main(): args, modules_list, modules_root_dir = pickle.load(fenv) fenv.close() kill_salome(args) + from searchFreePort import searchFreePort searchFreePort(args, 0) clt = useSalome(args, modules_list, modules_root_dir) return clt @@ -936,6 +831,7 @@ def main(): from salome_utils import getHostName print "runSalome running on %s" % getHostName() args, modules_list, modules_root_dir = setenv.get_config() + kill_salome(args) save_config = True if args.has_key('save_config'): @@ -946,6 +842,7 @@ def main(): test = False pass if test: + from searchFreePort import searchFreePort searchFreePort(args, save_config) pass # -- @@ -995,7 +892,7 @@ def foreGround(clt, args): server.CMD = [os.getenv("PYTHONBIN"), "-m", "killSalomeWithPort", "--spy", "%s"%(os.getpid()), "%s"%(port)] else: server.CMD = ["killSalomeWithPort.py", "--spy", "%s"%(os.getpid()), "%s"%(port)] - server.run() + server.run() # os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port)) # -- dt = 1.0 diff --git a/bin/salomeConsole.py b/bin/salomeConsole.py index a8c4a60a4..be01caa68 100755 --- a/bin/salomeConsole.py +++ b/bin/salomeConsole.py @@ -67,14 +67,14 @@ else: if rep == "y": filename=f break - + if filename != "": os.environ['OMNIORB_CONFIG']=filename else: rep= raw_input("Do you want to try a local session on port 2810 ? [y|n]") if rep == "y": # Try a local session running on port 2810 - sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810'] + sys.argv=sys.argv+['-ORBInitRef','NameService=corbaname::localhost:2810']#+['-ORBgiopMaxMsgSize','2097152000'] # 2 GBytes else: sys.exit(1) diff --git a/bin/salome_session.py b/bin/salome_session.py index d2ca5b094..17e984b9e 100644 --- a/bin/salome_session.py +++ b/bin/salome_session.py @@ -36,6 +36,7 @@ _session = None def startSession(modules=[]): global _session if _session: return + from searchFreePort import searchFreePort searchFreePort() _session = SalomeSession(modules) return @@ -51,59 +52,6 @@ def getShortHostName(): from salome_utils import getShortHostName return getShortHostName() -def searchFreePort(): - """ - Search free port for SALOME session. - Returns first found free port number. - """ - print "Searching a free port for naming service:", - from salome_utils import generateFileName, getHostName - hostname = getHostName() - NSPORT = 2810 - limit = NSPORT+100 - while 1: - print "%s "%(NSPORT), - status = os.system("netstat -ltn | grep -E :%s"%(NSPORT)) - if status: - home = os.getenv("HOME") - appli = os.getenv("APPLI") - kwargs={} - if appli is not None: - home = os.path.join(os.path.realpath(home), appli,"USERS") - kwargs["with_username"]=True - omniorb_config = generateFileName(home, prefix="omniORB", - extension="cfg", - hidden=True, - with_hostname=True, - with_port=NSPORT, - **kwargs) - f = open(omniorb_config, "w") - f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT)) - f.close() - os.environ['OMNIORB_CONFIG'] = omniorb_config - last_running_config = generateFileName(home, prefix="omniORB", - suffix="last", - extension="cfg", - hidden=True, - **kwargs) - os.environ['LAST_RUNNING_CONFIG'] = last_running_config - if os.access(last_running_config,os.F_OK): - os.unlink(last_running_config) - pass - os.symlink(omniorb_config,last_running_config) - print "- Ok" - break - if NSPORT == limit: - msg = "" - msg += "Can not find a free port to launch omniNames\n" - msg += "Kill the running servers and try again.\n" - raise RuntimeError, msg - NSPORT = NSPORT+1 - pass - os.environ['NSHOST'] = hostname - os.environ['NSPORT'] = str(NSPORT) - return NSPORT - class SalomeSession(object): """Salome session launcher""" diff --git a/bin/searchFreePort.py b/bin/searchFreePort.py new file mode 100644 index 000000000..08f789e36 --- /dev/null +++ b/bin/searchFreePort.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +def searchFreePort(args, save_config=1): + """ + Search free port for SALOME session. + Returns first found free port number. + """ + import sys, os, re, shutil + print "Searching for a free port for naming service:", + + # :NOTE: Under windows: + # netstat options -l and -t are unavailable + # grep command is unavailable + + from subprocess import Popen, PIPE + (stdout, stderr) = Popen(['netstat','-an'], stdout=PIPE).communicate() + import StringIO + buf = StringIO.StringIO(stdout) + ports = buf.readlines() + + # + def portIsUsed(port, data): + regObj = re.compile( ".*tcp.*:([0-9]+).*:.*listen", re.IGNORECASE ); + for item in data: + try: + p = int(regObj.match(item).group(1)) + if p == port: return True + pass + except: + pass + pass + return False + # + NSPORT=2810 + limit=NSPORT+100 + # + + while 1: + if not portIsUsed(NSPORT, ports): + print "%s - OK"%(NSPORT) + # + from salome_utils import generateFileName, getHostName + hostname = getHostName() + # + home = os.getenv("HOME") + appli = os.getenv("APPLI") + kwargs={} + if appli is not None: + home = os.path.join(os.path.realpath(home), appli,"USERS") + kwargs["with_username"]=True + # + from ORBConfigFile import writeORBConfigFile + writeORBConfigFile(home, hostname, NSPORT, kwargs) + + args['port'] = os.environ['NSPORT'] + # + if save_config: + last_running_config = generateFileName(home, prefix="omniORB", + suffix="last", + extension="cfg", + hidden=True, + **kwargs) + os.environ['LAST_RUNNING_CONFIG'] = last_running_config + try: + if sys.platform == "win32": + import shutil + shutil.copyfile(omniorb_config, last_running_config) + else: + try: + if os.access(last_running_config, os.F_OK): + os.remove(last_running_config) + except OSError: + pass + os.symlink(omniorb_config, last_running_config) + pass + pass + except: + 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 RuntimeError, msg + NSPORT=NSPORT+1 + pass + return