From 23308c5cb58044f2f7b7e9ffbbec0a9e65f7458c Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 22 Jun 2011 15:48:23 +0000 Subject: [PATCH] Improve runLightSalome.sh script: - add --help/-h, --version/-v, --modules/-m options - automatic detection of the available modules - correct environment set-up --- bin/runLightSalome.sh | 289 +++++++++++++++++++++++++++--------------- 1 file changed, 189 insertions(+), 100 deletions(-) diff --git a/bin/runLightSalome.sh b/bin/runLightSalome.sh index fe7dd662b..6695b8483 100755 --- a/bin/runLightSalome.sh +++ b/bin/runLightSalome.sh @@ -1,4 +1,5 @@ #!/bin/bash -f + # Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, @@ -23,128 +24,216 @@ # File : runLightSalome.sh # Author : Vadim SANDLER, Open CASCADE S.A.S, vadim.sandler@opencascade.com + + ### -# set default value for the LightAppConfig variable, which -# is necessary for loading of .ini or .xml resources file +# function show_usage() : print help an exit ### -# -if [ -z "$LightAppConfig" ] ; then - export LightAppConfig=${GUI_ROOT_DIR}/share/salome/resources/gui -else - export LightAppConfig=${LightAppConfig}:${GUI_ROOT_DIR}/share/salome/resources/gui -fi -if [ -z "$LightAppResources" ] ; then - export LightAppResources=${GUI_ROOT_DIR}/share/salome/resources/gui -else - export LightAppResources=${LightAppResources}:${GUI_ROOT_DIR}/share/salome/resources/gui -fi + +show_usage() { + local RET=0 + if [ $# -gt 0 ] ; then RET=$1 ; fi + local MOVE1="echo -en \\033[35G" + local MOVE2="echo -en \\033[22G" + echo + echo "Run standalone SALOME desktop". + echo + echo "Usage: $(basename $0) [options]" + echo + echo "Options:" + echo " * all options have both short and long format;" + echo " * some options require additional parameter (below referenced as )" + echo " which should be separated by = symbol from the option itself." + echo + echo -en " --help" + ${MOVE2} ; echo -en "(-h)" + ${MOVE1} ; echo "Display this information and exit." + echo -en " --version" + ${MOVE2} ; echo -en "(-v)" + ${MOVE1} ; echo "Print SALOME version and exit." + echo -en " --modules=" + ${MOVE2} ; echo -en "(-m)" + ${MOVE1} ; echo "List of modules, separated by comma, to be used within SALOME session." + echo + echo "Example:" + echo " $(basename $0) --modules=LIGHT,PYLIGHT" + echo + exit ${RET} +} ### -# process --modules=... command line option (get list of modules) +# function show_version() : print SALOME version an exit ### -modules="" - -for arg in X $* ; do - if [ "$arg" != "X" ] ; then - case $arg in - --modules=* ) modules=`echo $arg | awk -F= '{ print $2 }' | sed -e "s%,% %g"` ;; - *) ;; - esac +show_version() { + local RET=0 + local DIR=$(dirname $0) + if [ -z "${DIR}" ] ; then DIR=. ; fi + if [ -f ${DIR}/VERSION ] ; then + cat ${DIR}/VERSION + else + echo + echo "Error: can't find VERSION file" > /dev/stderr + echo + RET=1 fi -done - -modules="KERNEL GUI $modules" + exit ${RET} +} ### -# exclude modules duplication +# function option_modules() : process --modules / -m command line option ### -mods="" - -for mod in $modules ; do - echo $mods | grep -E "\<$mod\>" >/dev/null 2>&1 - if [ "$?" == "1" ] ; then - mods="$mods $mod" +option_modules() { + local MODS=`echo $1 | awk -F "=" '{ if(NF>1) print $2 ; else print $1 }'` + if [ "X${MODS}" = "X" ] ; then + echo + echo "Error: Please, specify list of modules" > /dev/stderr + echo + exit 1 fi -done + MODULES=`echo ${MODS} | sed -e "s%,% %g"` + return +} + ### -# set additional environment +# function run_light_salome(): run SALOME ### -python_version=`python -c "import sys; print sys.version[:3]" 2>/dev/null` - -MY_PATH="" -MY_LD_LIBRARY_PATH="" -MY_PYTHONPATH="" - -for mod in $mods ; do - if [ "$arg" != "X" ] ; then - root_dir=`printenv ${mod}_ROOT_DIR` - if [ "$root_dir" != "" ] ; then - mod_lower=`echo $mod | tr "A-Z" "a-z"` - if [ -d ${root_dir}/bin/salome ] ; then - if [ "${MY_PATH}" == "" ] ; then - MY_PATH=${root_dir}/bin/salome - else - MY_PATH=${MY_PATH}:${root_dir}/bin/salome - fi - fi - if [ -d ${root_dir}/lib/salome ] ; then - if [ "${MY_LD_LIBRARY_PATH}" == "" ] ; then - MY_LD_LIBRARY_PATH=${root_dir}/lib/salome - else - MY_LD_LIBRARY_PATH=${MY_LD_LIBRARY_PATH}:${root_dir}/lib/salome - fi +run_light_salome(){ + + local MODULES + + ### + # process command line options + ### + + local OPTION + while getopts ":-:hvm:" OPTION "$@" ; do + if [ "${OPTION}" = "-" ] ; then + case ${OPTARG} in + help ) show_usage ;; + version ) show_version ;; + modules* ) option_modules "${OPTARG}" ;; + * ) echo "!!!Wrong option!!!" ; exit 1 ;; + esac + else + case ${OPTION} in + h ) show_usage ;; + v ) show_version ;; + m* ) option_modules "${OPTARG}" ;; + ? ) echo "!!!Wrong option!!!" ; exit 1 ;; + esac + fi + done + shift $((OPTIND - 1)) + + ### + # by default try to detect all available modules + ### + + if [ -z "${MODULES}" ] ; then + local ENVVAR + local ROOTDIR + for ENVVAR in `env | awk -F= '{print $1}' | grep _ROOT_DIR` ; do + local MOD=`echo $ENVVAR | awk -F_ '{print $1}'` + local LMOD=`echo ${MOD} | tr 'A-Z' 'a-z'` + ROOTDIR=`printenv ${ENVVAR}` + if [ -f ${ROOTDIR}/share/salome/resources/${LMOD}/LightApp.xml ] || [ -f ${ROOTDIR}/share/salome/resources/LightApp.xml ] ; then + MODULES="${MODULES} ${MOD}" fi - if [ "${python_version}" != "" ] ; then - if [ -d ${root_dir}/bin/salome ] ; then - if [ "${MY_PYTHONPATH}" == "" ] ; then - MY_PYTHONPATH=${root_dir}/bin/salome - else - MY_PYTHONPATH=${MY_PYTHONPATH}:${root_dir}/bin/salome - fi - fi - if [ -d ${root_dir}/lib/salome ] ; then - if [ "${MY_PYTHONPATH}" == "" ] ; then - MY_PYTHONPATH=${root_dir}/lib/salome - else - MY_PYTHONPATH=${MY_PYTHONPATH}:${root_dir}/lib/salome - fi - fi - if [ -d ${root_dir}/lib/python${python_version}/site-packages/salome ] ; then - if [ "${MY_PYTHONPATH}" == "" ] ; then - MY_PYTHONPATH=${root_dir}/lib/python${python_version}/site-packages/salome - else - MY_PYTHONPATH=${MY_PYTHONPATH}:${root_dir}/lib/python${python_version}/site-packages/salome - fi - fi + done + fi + + ### + # initial environment + ### + + if [ -z "${LightAppResources}" ] ; then + export LightAppResources=${GUI_ROOT_DIR}/share/salome/resources/gui + else + export LightAppResources=${LightAppResources}:${GUI_ROOT_DIR}/share/salome/resources/gui + fi + + MODULES="KERNEL GUI ${MODULES}" + + ### + # exclude modules duplication + ### + + local MODS="" + local MOD + for MOD in ${MODULES} ; do + echo ${MODS} | grep -E "\<${MOD}\>" >/dev/null 2>&1 + if [ "$?" == "1" ] ; then + MODS="${MODS} ${MOD}" + fi + done + MODULES=${MODS} + + ### + # set additional environment + ### + + local PVERSION=`python -c "import sys; print sys.version[:3]" 2>/dev/null` + + local MY_PATH="" + local MY_LD_LIBRARY_PATH="" + local MY_PYTHONPATH="" + + for MOD in ${MODULES} ; do + local ROOTDIR=`printenv ${MOD}_ROOT_DIR` + if [ -z "${ROOTDIR}" ] ; then continue ; fi + local LMOD=`echo ${MOD} | tr 'A-Z' 'a-z'` + if [ -d ${ROOTDIR}/bin/salome ] ; then + MY_PATH=${MY_PATH}:${ROOTDIR}/bin/salome + fi + if [ -d ${ROOTDIR}/lib/salome ] ; then + MY_LD_LIBRARY_PATH=${MY_LD_LIBRARY_PATH}:${ROOTDIR}/lib/salome + fi + if [ "${PVERSION}" != "" ] ; then + if [ -d ${ROOTDIR}/bin/salome ] ; then + MY_PYTHONPATH=${MY_PYTHONPATH}:${ROOTDIR}/bin/salome fi - if [ "$mod" != "KERNEL" ] && [ "$mod" != "GUI" ] ; then - export LightAppConfig=${LightAppConfig}:${root_dir}/share/salome/resources/${mod_lower} + if [ -d ${ROOTDIR}/lib/salome ] ; then + MY_PYTHONPATH=${MY_PYTHONPATH}:${ROOTDIR}/lib/salome fi - if [ "${SALOMEPATH}" == "" ] ; then - export SALOMEPATH=${root_dir} - else - export SALOMEPATH=${SALOMEPATH}:${root_dir} + if [ -d ${ROOTDIR}/lib/python${PVERSION}/site-packages/salome ] ; then + MY_PYTHONPATH=${MY_PYTHONPATH}:${ROOTDIR}/lib/python${PVERSION}/site-packages/salome fi fi - fi -done - -if [ "${MY_PATH}" != "" ] ; then - export PATH=${MY_PATH}:${PATH} -fi -if [ "${MY_LD_LIBRARY_PATH}" != "" ] ; then - export LD_LIBRARY_PATH=${MY_LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} -fi -if [ "${PYTHONPATH}" != "" ] ; then - export PYTHONPATH=${MY_PYTHONPATH}:${PYTHONPATH} -fi + if [ -f ${ROOTDIR}/share/salome/resources/${LMOD}/LightApp.xml ] ; then + export LightAppConfig=${LightAppConfig}:${ROOTDIR}/share/salome/resources/${LMOD} + elif [ -f ${ROOTDIR}/share/salome/resources/LightApp.xml ] ; then + export LightAppConfig=${LightAppConfig}:${ROOTDIR}/share/salome/resources + fi + export SALOMEPATH=${SALOMEPATH}:${ROOTDIR} + done + + PATH=${MY_PATH}:${PATH} + PATH=`echo ${PATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g"` + export PATH + LD_LIBRARY_PATH=${MY_LD_LIBRARY_PATH}:${LD_LIBRARY_PATH} + LD_LIBRARY_PATH=`echo ${LD_LIBRARY_PATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g"` + export LD_LIBRARY_PATH + PYTHONPATH=${MY_PYTHONPATH}:${PYTHONPATH} + PYTHONPATH=`echo ${PYTHONPATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g"` + export PYTHONPATH + LightAppConfig=`echo ${LightAppConfig} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g"` + export LightAppConfig + SALOMEPATH=`echo ${SALOMEPATH} | sed -e "s,^:,,;s,:$,,;s,::\+,:,g"` + export SALOMEPATH + + ### + # start application + ### + + SUITApp LightApp "$*" & +} ### -# start application +# call wrapper function (entry point) ### -SUITApp LightApp $* & +run_light_salome "$@" \ No newline at end of file -- 2.39.2