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
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
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# -* Makefile *-
+# -* Makefile *-
# Author : Guillaume Boulant (CSSI)
# Module : KERNEL
# $Header$
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 \
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
--- /dev/null
+#!/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
. ${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
. ${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
# --- 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
. ${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
# --- 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 "$*"
# --- 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} "
let NSPORT=NSPORT+1
done
}
-
if __name__ == "__main__":
killAllPorts()
pass
-
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(),
- 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
except:
pass
pass
-
+
def killMyPort(port):
"""
Kill SALOME session running on the specified 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)
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
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
#
appliCleanOmniOrbConfig(port)
pass
-
+
def killNotifdAndClean(port):
"""
Kill notifd daemon and clean application running on the specified port.
# 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
# ... 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))
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():
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) :
else:
if verbose(): print "Configure parser: Error : file %s does not exist" % absfname
return
-
+
# importing file
try:
# copy current options
except:
if verbose(): print "Configure parser: Error : can not read configuration file %s" % absfname
pass
-
+
# -----------------------------------------------------------------------------
# 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)
except Exception, inst:
print str(currentPort) + ": " + str(inst.args);
currentPort = currentPort+step;
-
-
-
-
+
+
+
+
if (portFound != 1) :
currentPort = -1;
return currentPort;
if (len(sys.argv) > 1) and sys.argv[1] == "-nothing" :
print "port:" + str(freePort);
sys.exit(0)
-
-
-
if freePort < 0 :
print
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";
else :
#copy the file
shutil.copy(omniCfgFilePath, omniCfgCurrent);
-
+
omniCfgFilePath = omniCfgCurrent;
-
-
-
+
## 2. Set the OMNIORB_CONFIG environment variable
os.environ['OMNIORB_CONFIG']=omniCfgFilePath;
if os.path.isfile(runSalomePyFilePath) :
execfile(runSalomePyFilePath);
-
"""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 {})
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']:
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)
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:
time.sleep(aDelta)
pass
pass
-
+
if theTypObj is None:
return anObj
except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
obj = None
return obj
-
+
# --------------------------------------------------------------------------
def waitLogger(self,name,typobj=None,maxcount=40):
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
-
# 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
# - 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
# 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
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:
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:
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
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[:]
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','(',')']
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']:
self.CMD = ["xterm", "-e", "gdb", "--command=.gdbinit4salome", self.CMD[0]]
pass
pass
-
+
if self.args["valgrind_session"]:
l = ["valgrind"]
val = os.getenv("VALGRIND_OPTIONS")
pass
self.CMD = l + self.CMD
pass
-
+
# ---
class LauncherServer(Server):
import SALOME_Session_idl
session=clt.waitNS("/Kernel/Session",SALOME.Session)
session.GetInterface()
-
+
# -----------------------------------------------------------------------------
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
#
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
os.environ['OMNIORB_CONFIG'] = last_running_config
pass
pass
-
+
#
# Initialisation ORB and Naming Service
#
-
+
clt=orbmodule.client(args)
#
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'):
if sys.platform != "win32":
if verbose(): print "Notify Server to launch"
-
+
myServer=NotifyServer(args,modules_root_dir)
myServer.run()
#
# Launch LauncherServer
#
-
+
myCmServer = LauncherServer(args)
myCmServer.setpath(modules_list,modules_root_dir)
myCmServer.run()
from Utils_Identity import getShortHostName
-
+
if os.getenv("HOSTNAME") == None:
if os.getenv("HOST") == None:
os.environ["HOSTNAME"]=getShortHostName()
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":
#
# Wait until Session Server is registered in naming service
#
-
+
if args["gui"]:
-##----------------
+##----------------
import Engines
import SALOME
import SALOMEDS
# additionnal external python interpreters
#
nbaddi=0
-
+
try:
if 'interp' in args:
nbaddi = args['interp']
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):
import readline
except ImportError:
pass
-
+
return clt
# -----------------------------------------------------------------------------
show registered objects in Naming Service.
"""
global process_id
-
+
clt=None
try:
clt = startSalome(args, modules_list, modules_root_dir)
print
print
print "--- Error during Salome launch ---"
-
+
#print process_id
from addToKillList import addToKillList
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):
args['shutdown_servers'] = __utils__(args['port'])
pass
pass
-
+
# run python scripts, passed via --execute option
toimport = []
if args.has_key('pyscript'):
pass
pass
return clt
-
+
def execScript(script_path):
print 'executing', script_path
sys.path.insert(0, os.path.dirname(script_path))
# -----------------------------------------------------------------------------
-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"]
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
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'):
test = False
pass
if test:
+ from searchFreePort import searchFreePort
searchFreePort(args, save_config)
pass
# --
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
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)
def startSession(modules=[]):
global _session
if _session: return
+ from searchFreePort import searchFreePort
searchFreePort()
_session = SalomeSession(modules)
return
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"""
--- /dev/null
+#!/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