From: caremoli Date: Thu, 8 Jan 2009 17:28:49 +0000 (+0000) Subject: CCAR: these modifications are mainly for the salome virtual application X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=be332e164bc8b19fe00af26e0efb61036c0a973a;p=modules%2Fkernel.git CCAR: these modifications are mainly for the salome virtual application They allow one salome virtual application to be used by several users with different logins. That was not possible before. shutdownSalome has been modified to correctly handle salome virtual application and to do same job from GUI or from console --- diff --git a/bin/appli_clean.sh b/bin/appli_clean.sh index 9ea7ae8a7..a5413a737 100644 --- a/bin/appli_clean.sh +++ b/bin/appli_clean.sh @@ -22,4 +22,4 @@ # #clean appli # -rm -rf bin lib share doc idl env.d envd getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml *.pyc *~ .bashrc +rm -rf bin lib share doc idl env.d envd USERS getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml *.pyc *~ .bashrc diff --git a/bin/appli_gen.py b/bin/appli_gen.py index 4fa0e2dcf..c57f4c25d 100644 --- a/bin/appli_gen.py +++ b/bin/appli_gen.py @@ -26,11 +26,12 @@ usage="""usage: %prog [options] Typical use is: python appli_gen.py -Use with options: - python appli_gen.py --prefix= --config= +Typical use with options is: + python appli_gen.py --verbose --prefix= --config= """ import os, glob, string, sys, re +import shutil import xml.sax import optparse import virtual_salome @@ -130,7 +131,16 @@ class params: # ----------------------------------------------------------------------------- -def install(prefix,config_file): +def makedirs(namedir): + if os.path.exists(namedir): + dirbak=namedir+".bak" + if os.path.exists(dirbak): + shutil.rmtree(dirbak) + os.rename(namedir,dirbak) + os.listdir(dirbak) #sert seulement a mettre a jour le systeme de fichier sur certaines machines + os.makedirs(namedir) + +def install(prefix,config_file,verbose=0): home_dir=os.path.abspath(os.path.expanduser(prefix)) filename=os.path.abspath(os.path.expanduser(config_file)) _config={} @@ -149,14 +159,15 @@ def install(prefix,config_file): print "Configure parser: Error : can not read configuration file %s, check existence and rights" % filename pass - for cle in _config.keys(): - print cle, _config[cle] - pass + if verbose: + for cle in _config.keys(): + print cle, _config[cle] + pass for module in _config["modules"]: print "--- add module ", module, _config[module] options = params() - options.verbose=0 + options.verbose=verbose options.clear=0 options.prefix=home_dir options.module=_config[module] @@ -259,6 +270,11 @@ def install(prefix,config_file): f.write(command) f.close() + #Add USERS directory with 777 permission to store users configuration files + users_dir=os.path.join(home_dir,'USERS') + makedirs(users_dir) + os.chmod(users_dir, 0777) + def main(): parser = optparse.OptionParser(usage=usage) @@ -268,8 +284,11 @@ def main(): parser.add_option('--config', dest="config", default='config_appli.xml', help="XML configuration file (default config_appli.xml)") + parser.add_option('-v', '--verbose', action='count', dest='verbose', + default=0, help="Increase verbosity") + options, args = parser.parse_args() - install(prefix=options.prefix,config_file=options.config) + install(prefix=options.prefix,config_file=options.config,verbose=options.verbose) pass # ----------------------------------------------------------------------------- diff --git a/bin/appliskel/killCurrentPort b/bin/appliskel/killCurrentPort index d02c7f28b..86a3f499a 100755 --- a/bin/appliskel/killCurrentPort +++ b/bin/appliskel/killCurrentPort @@ -32,10 +32,10 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py` # --- find omniORB configuration relative to current session if any -fileOmniConfig=${HOME}/${APPLI}/.omniORB_last.cfg +fileOmniConfig=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg if [ -f $fileOmniConfig ]; then - OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_last.cfg + OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg export OMNIORB_CONFIG fi diff --git a/bin/appliskel/runRemote.sh b/bin/appliskel/runRemote.sh index 5a50a1e46..dd5258e4f 100755 --- a/bin/appliskel/runRemote.sh +++ b/bin/appliskel/runRemote.sh @@ -50,7 +50,7 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py` # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME -OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_$1_$2.cfg +OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_$1_$2.cfg export OMNIORB_CONFIG NSHOST=$1 export NSHOST diff --git a/bin/appliskel/runSession b/bin/appliskel/runSession index 5a14c9461..716fbe6d9 100755 --- a/bin/appliskel/runSession +++ b/bin/appliskel/runSession @@ -36,20 +36,32 @@ export APPLI=`${APPLI_HOME}/getAppliPath.py` . ${HOME}/${APPLI}/envd ${HOME}/${APPLI} -# --- set omniORB configuration to current session if any +if test "x$1" == "xNSPORT"; then + NSPORT=$2 + export NSPORT + myhost=`hostname` + OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${myhost}_${NSPORT}.cfg + export OMNIORB_CONFIG + NSHOST=${myhost} + export NSHOST + shift 2 +else -fileOmniConfig=${HOME}/${APPLI}/.omniORB_last.cfg + # --- set omniORB configuration to current session if any -if [ -f $fileOmniConfig ]; then - OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_last.cfg - export OMNIORB_CONFIG + fileOmniConfig=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg - # --- set environment variables for port and hostname of NamingService + if [ -f $fileOmniConfig ]; then + OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg + export OMNIORB_CONFIG - NSHOST=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py host` - export NSHOST - NSPORT=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port` - export NSPORT + # --- set environment variables for port and hostname of NamingService + + NSHOST=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py host` + export NSHOST + NSPORT=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port` + export NSPORT + fi fi # --- invoke shell with or without args diff --git a/bin/appliskel/runTests b/bin/appliskel/runTests index a13b1a171..2d9d9d42d 100755 --- a/bin/appliskel/runTests +++ b/bin/appliskel/runTests @@ -43,7 +43,7 @@ searchFreePort() { if [ -z "$aRes" ]; then echo ${NSPORT} - Ok local myhost=`hostname` - OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg + OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${myhost}_${NSPORT}.cfg export OMNIORB_CONFIG export NSPORT NSHOST=${myhost} @@ -51,7 +51,7 @@ searchFreePort() { local initref="NameService=corbaname::"`hostname`":$NSPORT" #echo "ORBInitRef $initref" > $OMNIORB_CONFIG echo "InitRef = $initref" > $OMNIORB_CONFIG - LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_test.cfg + 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} diff --git a/bin/appliskel/searchFreePort.sh b/bin/appliskel/searchFreePort.sh index 33fc3bea9..ad8af9f3d 100755 --- a/bin/appliskel/searchFreePort.sh +++ b/bin/appliskel/searchFreePort.sh @@ -34,7 +34,7 @@ searchFreePort() { if [ -z "$aRes" ]; then echo ${NSPORT} - Ok local myhost=`hostname` - OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg + OMNIORB_CONFIG=${HOME}/${APPLI}/USERS/.omniORB_${USER}_${myhost}_${NSPORT}.cfg export OMNIORB_CONFIG export NSPORT NSHOST=${myhost} @@ -42,7 +42,7 @@ searchFreePort() { local initref="NameService=corbaname::"`hostname`":$NSPORT" #echo "ORBInitRef $initref" > $OMNIORB_CONFIG echo "InitRef = $initref" > $OMNIORB_CONFIG - LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_last.cfg + 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} diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 2933cf267..4403a8bc2 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -20,8 +20,10 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -import os, sys, pickle, signal, commands +import os, sys, pickle, signal, commands,glob from launchConfigureParser import verbose +import Utils_Identity +import salome_utils def getPiDict(port,appname='salome',full=True,hidden=True): """ @@ -65,8 +67,8 @@ def getPiDict(port,appname='salome',full=True,hidden=True): def appliCleanOmniOrbConfig(port): """ Remove omniorb config files related to the port in SALOME application: - - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg - - ${HOME}/${APPLI}/.omniORB_last.cfg + - ${HOME}/${APPLI}/USERS/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg + - ${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg the last is removed only if the link points to the first file. """ from salome_utils import generateFileName @@ -76,13 +78,15 @@ def appliCleanOmniOrbConfig(port): #Run outside application context pass else: - dir = os.path.join(home, appli) + dir = os.path.join(home, appli,"USERS") omniorb_config = generateFileName(dir, prefix="omniORB", extension="cfg", hidden=True, + with_username=True, with_hostname=True, with_port=port) last_running_config = generateFileName(dir, prefix="omniORB", + with_username=True, suffix="last", extension="cfg", hidden=True) @@ -97,6 +101,20 @@ def appliCleanOmniOrbConfig(port): if os.access(omniorb_config,os.F_OK): os.remove(omniorb_config) pass + + #try to relink last.cfg to an existing config file if any + files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(), + "USERS",".omniORB_"+salome_utils.getUserName()+"_*.cfg")) + current_config=None + current=0 + for f in files: + stat=os.stat(f) + if stat.st_atime > current: + current=stat.st_atime + current_config=f + if current_config: + os.symlink(os.path.normpath(current_config), last_running_config) + pass pass @@ -190,6 +208,29 @@ def killMyPort(port): appliCleanOmniOrbConfig(port) pass +def killNotifdAndClean(port): + """ + Kill notifd daemon and clean application running on the specified port. + Parameters: + - port - port number + """ + try: + filedict=getPiDict(port) + f=open(filedict, 'r') + pids=pickle.load(f) + for d in pids: + for pid,process in d.items(): + if 'notifd' in process: + cmd='kill -9 %d'% pid + os.system(cmd) + os.remove(filedict) + except: + #import traceback + #traceback.print_exc() + pass + + appliCleanOmniOrbConfig(port) + if __name__ == "__main__": for port in sys.argv[1:]: killMyPort(port) diff --git a/bin/runSalome.py b/bin/runSalome.py index 3508a6cc8..c0c1ad1b7 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -771,13 +771,17 @@ def searchFreePort(args, save_config=1): # home = os.getenv("HOME") appli = os.getenv("APPLI") - if appli is not None: home = os.path.join(home, appli) + kwargs={} + if appli is not None: + home = os.path.join(home, appli,"USERS") + kwargs["with_username"]=True # omniorb_config = generateFileName(home, prefix="omniORB", extension="cfg", hidden=True, with_hostname=True, - with_port=NSPORT) + with_port=NSPORT, + **kwargs) orbdata = [] initref = "NameService=corbaname::%s:%s"%(hostname, NSPORT) import CORBA @@ -804,7 +808,8 @@ def searchFreePort(args, save_config=1): last_running_config = generateFileName(home, prefix="omniORB", suffix="last", extension="cfg", - hidden=True) + hidden=True, + **kwargs) try: if sys.platform == "win32": import shutil diff --git a/bin/salomeConsole.py b/bin/salomeConsole.py index d7916fe97..56c805c14 100755 --- a/bin/salomeConsole.py +++ b/bin/salomeConsole.py @@ -44,13 +44,15 @@ import SALOME_ModuleCatalog reload(Engines) reload(SALOME) reload(SALOMEDS) +import salome_utils import LifeCycleCORBA import orbmodule from runSalome import * import Utils_Identity -files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),".omni*.cfg")) +files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(), + "USERS",".omniORB_"+salome_utils.getUserName()+"_*.cfg")) filename="" if len(files)==1: diff --git a/bin/salome_session.py b/bin/salome_session.py index 6a5d2f82b..9c648214d 100644 --- a/bin/salome_session.py +++ b/bin/salome_session.py @@ -60,12 +60,16 @@ def searchFreePort(): if status: home = os.getenv("HOME") appli = os.getenv("APPLI") - if appli is not None: home = os.path.join(home, appli) + kwargs={} + if appli is not None: + home = os.path.join(home, appli,"USERS") + kwargs["with_username"]=True omniorb_config = generateFileName(home, prefix="omniORB", extension="cfg", hidden=True, with_hostname=True, - with_port=NSPORT) + with_port=NSPORT, + **kwargs) f = open(omniorb_config, "w") f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT)) f.close() @@ -73,7 +77,8 @@ def searchFreePort(): last_running_config = generateFileName(home, prefix="omniORB", suffix="last", extension="cfg", - hidden=True) + 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) diff --git a/bin/salome_utils.py b/bin/salome_utils.py index 6d18fed9f..ab9c0669c 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -344,4 +344,4 @@ def generateFileName( dir, prefix = None, suffix = None, extension = None, name = os.path.join( dir, name ) pass pass - return name + return os.path.normpath(name) diff --git a/bin/virtual_salome.py b/bin/virtual_salome.py index b7f0e6708..971ab8c39 100644 --- a/bin/virtual_salome.py +++ b/bin/virtual_salome.py @@ -40,7 +40,8 @@ verbose=0 def mkdir(path): """Create a directory and all the intermediate directories if path does not exist""" if not os.path.exists(path): - print 'Creating %s' % path + if verbose: + print 'Creating %s' % path os.makedirs(path) else: if verbose: @@ -58,7 +59,8 @@ def symlink(src, dest): pass os.symlink(src, dest) else: - print 'Symlink %s already exists' % dest + if verbose: + print 'Symlink %s already exists' % dest pass pass @@ -89,6 +91,7 @@ def get_lib_dir(): # ----------------------------------------------------------------------------- def link_module(options): + global verbose if not options.module: print "Option module is mandatory" @@ -99,6 +102,8 @@ def link_module(options): print "Module %s does not exist" % module_dir return + verbose = options.verbose + home_dir = os.path.expanduser(options.prefix) #try to find python version of salome application and put it in versio pys=[os.path.split(s)[1] for s in glob.glob(os.path.join(home_dir,get_lib_dir(),"python*.*"))] @@ -148,8 +153,6 @@ def link_module(options): sharedoc_gui_dir=os.path.join(home_dir,'share','doc','salome','gui') sharedoc_tui_dir=os.path.join(home_dir,'share','doc','salome','tui') - verbose = options.verbose - if options.clear: rmtree(bin_dir) rmtree(idl_dir) @@ -168,7 +171,8 @@ def link_module(options): pass pass else: - print module_bin_dir, " doesn't exist" + if verbose: + print module_bin_dir, " doesn't exist" pass #directory idl/salome : create it and link content @@ -177,7 +181,8 @@ def link_module(options): for fn in os.listdir(module_idl_dir): symlink(os.path.join(module_idl_dir, fn), os.path.join(idl_dir, fn)) else: - print module_idl_dir, " doesn't exist" + if verbose: + print module_idl_dir, " doesn't exist" #directory lib/salome : create it and link content if os.path.exists(module_lib_dir): @@ -187,7 +192,8 @@ def link_module(options): pass pass else: - print module_lib_dir, " doesn't exist" + if verbose: + print module_lib_dir, " doesn't exist" pass #directory lib/pyversio/site-packages/salome : create it and link content @@ -205,7 +211,8 @@ def link_module(options): pass pass else: - print module_lib_py_shared_dir, " doesn't exist" + if verbose: + print module_lib_py_shared_dir, " doesn't exist" pass #directory share/doc/salome (KERNEL doc) : create it and link content diff --git a/bin/waitNS.sh b/bin/waitNS.sh index 2727217cf..249f17d18 100755 --- a/bin/waitNS.sh +++ b/bin/waitNS.sh @@ -22,7 +22,7 @@ # status=1 while [ $status -ne 0 ]; do - ls $HOME/$APPLI/.omniORB_last.cfg >& /dev/null + ls $HOME/$APPLI/USERS/.omniORB_${USER}_last.cfg >& /dev/null status=$? sleep 1 echo -n "#" diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 70f920c7c..e6e5936e7 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -541,16 +541,8 @@ void SALOME_LifeCycleCORBA::killOmniNames() // NPAL 18309 (Kill Notifd) if ( !portNumber.empty() ) { - string cmd = ("import pickle, os; "); - cmd += string("from killSalomeWithPort import getPiDict; "); - cmd += string("filedict=getPiDict(") + portNumber + "); "; - cmd += string("f=open(filedict, 'r'); "); - cmd += string("pids=pickle.load(f); "); - cmd += string("m={}; "); - cmd += string("[ m.update(i) for i in pids ]; "); - cmd += string("pids=filter(lambda a: 'notifd' in m[a], m.keys()); "); - cmd += string("[ os.system('kill -9 %d'%pid) for pid in pids ]; "); - cmd += string("os.remove(filedict); "); + string cmd = ("from killSalomeWithPort import killNotifdAndClean; "); + cmd += string("killNotifdAndClean(") + portNumber + "); "; cmd = string("python -c \"") + cmd +"\" >& /dev/null"; MESSAGE(cmd); system( cmd.c_str() );