#
#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
usage="""usage: %prog [options]
Typical use is:
python appli_gen.py
-Use with options:
- python appli_gen.py --prefix=<install directory> --config=<configuration file>
+Typical use with options is:
+ python appli_gen.py --verbose --prefix=<install directory> --config=<configuration file>
"""
import os, glob, string, sys, re
+import shutil
import xml.sax
import optparse
import virtual_salome
# -----------------------------------------------------------------------------
-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={}
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]
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)
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
# -----------------------------------------------------------------------------
# --- 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
# --- 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
. ${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
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}
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}
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}
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}
#
# 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):
"""
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
#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)
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
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)
#
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
last_running_config = generateFileName(home, prefix="omniORB",
suffix="last",
extension="cfg",
- hidden=True)
+ hidden=True,
+ **kwargs)
try:
if sys.platform == "win32":
import shutil
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:
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()
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)
name = os.path.join( dir, name )
pass
pass
- return name
+ return os.path.normpath(name)
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:
pass
os.symlink(src, dest)
else:
- print 'Symlink %s already exists' % dest
+ if verbose:
+ print 'Symlink %s already exists' % dest
pass
pass
# -----------------------------------------------------------------------------
def link_module(options):
+ global verbose
if not options.module:
print "Option module is mandatory"
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*.*"))]
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)
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
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):
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
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
#
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 "#"
// 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() );