From 23775b380d49de61f3a3ee31eb6e84c17670a34d Mon Sep 17 00:00:00 2001 From: prascle Date: Tue, 28 Mar 2006 17:07:36 +0000 Subject: [PATCH] corrections for batch mode --- bin/appliskel/runAppli | 6 +- bin/appliskel/runConsole | 4 +- bin/appliskel/runSession | 10 ++-- bin/killSalomeWithPort.py | 5 +- bin/salomeConsole.py | 7 +-- bin/salome_session.py | 86 +++++++++++++++++++++++++++++ src/KERNEL_PY/salome.py | 4 +- src/KERNEL_PY/salome_iapp.py | 101 +++++++++++++++++++++++++++++++--- src/KERNEL_PY/salome_study.py | 5 +- 9 files changed, 203 insertions(+), 25 deletions(-) create mode 100644 bin/salome_session.py diff --git a/bin/appliskel/runAppli b/bin/appliskel/runAppli index 1d86ad3d5..e28e9c9d4 100755 --- a/bin/appliskel/runAppli +++ b/bin/appliskel/runAppli @@ -1,8 +1,10 @@ #!/bin/bash +APPLI_HOME=`dirname $0` + # --- retrieve APPLI path, relative to $HOME, set ${APPLI} -. `dirname $0`/setAppliPath.sh +. ${APPLI_HOME}/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) @@ -10,7 +12,7 @@ # --- define port for CORBA naming service -. `dirname $0`/searchFreePort.sh +. ${HOME}/${APPLI}/searchFreePort.sh searchFreePort # --- if mpi lam, start lam (seems safe to be done several times) diff --git a/bin/appliskel/runConsole b/bin/appliskel/runConsole index caeabbdd6..c94a02fcf 100755 --- a/bin/appliskel/runConsole +++ b/bin/appliskel/runConsole @@ -1,8 +1,10 @@ #!/bin/bash +APPLI_HOME=`dirname $0` + # --- retrieve APPLI path, relative to $HOME, set ${APPLI} -. `dirname $0`/setAppliPath.sh +. ${APPLI_HOME}/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) diff --git a/bin/appliskel/runSession b/bin/appliskel/runSession index c0a26ba13..69573bf10 100755 --- a/bin/appliskel/runSession +++ b/bin/appliskel/runSession @@ -5,9 +5,11 @@ # Use it without args to run an interactive shell under Salome env # +APPLI_HOME=`dirname $0` + # --- retrieve APPLI path, relative to $HOME, set ${APPLI} -. `dirname $0`/setAppliPath.sh +. ${APPLI_HOME}/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) @@ -30,11 +32,11 @@ if [ -f $fileOmniConfig ]; then export NSPORT fi -# --- invoque shell with or without args +# --- invoke shell with or without args if [ $# -ne 0 ] ; then - ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/sh --rcfile ${HOME}/${APPLI}/.bashrc -c "$*" + ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py $* else - ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/sh --rcfile ${HOME}/${APPLI}/.bashrc + ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py /bin/bash --rcfile ${HOME}/${APPLI}/.bashrc fi diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 9f0cd0dd9..bb1bec3b0 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -65,8 +65,9 @@ def killMyPort(port): except: pass os.remove(filedict) - pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"") - a = "" + cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"' + pid = commands.getoutput(cmd) + a = "" while pid != "" and len(a.split(" ")) < 2: a = commands.getoutput("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid") pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"") diff --git a/bin/salomeConsole.py b/bin/salomeConsole.py index 5ce7cec64..9373022d2 100755 --- a/bin/salomeConsole.py +++ b/bin/salomeConsole.py @@ -79,7 +79,6 @@ clt.showNS() session=clt.waitNS("/Kernel/Session") catalog=clt.waitNS("/Kernel/ModulCatalog") studyMgr=clt.waitNS("/myStudyManager") -lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb) - -#c=lcc.FindOrStartContainer("","totoPy") -#print c +import salome +salome.salome_init() +from salome import lcc diff --git a/bin/salome_session.py b/bin/salome_session.py new file mode 100644 index 000000000..354bb3350 --- /dev/null +++ b/bin/salome_session.py @@ -0,0 +1,86 @@ + +import os +import sys +import string +import socket + +_session = None + +def startSession(modules=[]): + global _session + if _session: return + searchFreePort() + _session = SalomeSession(modules) + return + +def getShortHostName(): + """ + gives Hostname without domain extension. + SALOME naming service needs short Hostnames (without domain extension). + HOSTNAME is not allways defined in environment, + socket.gethostname() gives short or complete Hostname, depending on + defined aliases. + """ + return string.split(socket.gethostname(),'.')[0] + +def searchFreePort(): + print "Searching a free port for naming service:", + NSPORT=2810 + limit=NSPORT + limit=limit+100 + while 1: + print "%s "%(NSPORT), + status = os.system("netstat -ltn | grep -E :%s"%(NSPORT)) + if status: + home = os.environ['HOME'] + appli=os.environ.get("APPLI") + if appli is None: + #Run outside application context + home=home + else: + home='%s/%s'%(home,appli) + hostname=getShortHostName() + omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, NSPORT) + os.environ['OMNIORB_CONFIG'] = omniorb_config + f = open(omniorb_config, "w") + f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT)) + f.close() + last_running_config = '%s/.omniORB_%s_last.cfg'%(home, hostname) + 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) + # LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg + print "- Ok" + break + if NSPORT == limit: + msg = "" + msg += "I Can't find a free port to launch omniNames\n" + msg += "I suggest you to kill the running servers and try again.\n" + raise msg + NSPORT=NSPORT+1 + pass + return NSPORT + + +class SalomeSession(object): + import runSalome + import killSalomeWithPort + import killSalome + def __init__(self, modules): + import runSalome + sys.argv = ["dummy.py"] + sys.argv += ["--terminal"] + if modules: + sys.argv += ['--modules=%s'%(",".join(modules))] + pass + runSalome.clt, runSalome.args = runSalome.main() + import salome + salome.salome_init() + return + def __del__(self): + import runSalome + runSalome.killLocalPort() + return + pass diff --git a/src/KERNEL_PY/salome.py b/src/KERNEL_PY/salome.py index d853b2cb6..f7e0099a4 100755 --- a/src/KERNEL_PY/salome.py +++ b/src/KERNEL_PY/salome.py @@ -30,7 +30,7 @@ from salome_study import * from salome_iapp import * salome_initial=1 -def salome_init(theStudyId=0): +def salome_init(theStudyId=0,embedded=0): """ Performs only once SALOME general purpose intialisation for scripts. optional argument : theStudyId @@ -58,7 +58,7 @@ def salome_init(theStudyId=0): if salome_initial: salome_initial=0 - sg = salome_iapp_init() + sg = salome_iapp_init(embedded) orb, lcc, naming_service, cm = salome_kernel_init() myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId) diff --git a/src/KERNEL_PY/salome_iapp.py b/src/KERNEL_PY/salome_iapp.py index e6ebcaf16..4752be138 100644 --- a/src/KERNEL_PY/salome_iapp.py +++ b/src/KERNEL_PY/salome_iapp.py @@ -55,20 +55,107 @@ def SalomeGUIgetAllSelected(self): #-------------------------------------------------------------------------- +def hasDesktop(): + return IN_SALOME_GUI + + #-------------------------------------------------------------------------- + salome_iapp_initial = 1 -def salome_iapp_init(): +class SalomeOutsideGUI: + """ + Provides a replacement for class SalomeGUI outside GUI process. + Do almost nothing + """ + global myStudyId, myStudyName + + def hasDesktop(self): + return false + + def updateObjBrowser(self, bid): + print "SalomeOutsideGUI: no objectBrowser update outside GUI" + pass + + def getActiveStudyId(self): + print "SalomeOutsideGUI.getActiveStudyId: avoid use outside GUI" + return myStudyId + + def getActiveStudyName(self): + print "SalomeOutsideGUI.getActiveStudyName: avoid use outside GUI" + return myStudyName + + def SelectedCount(self): + print "SalomeOutsideGUI: no selection mecanism available outside GUI" + return 0 + + def getSelected(self, i): + print "SalomeOutsideGUI: no selection mecanism available outside GUI" + return none + + def AddIObject(self, Entry): + print "SalomeOutsideGUI.AddIOObject: not available outside GUI" + pass + + def RemoveIObject(self, Entry): + print "SalomeOutsideGUI.REmoveIOObject: not available outside GUI" + pass + + def ClearIObjects(self): + print "SalomeOutsideGUI.ClearIOObject: not available outside GUI" + pass + + def Display(self, Entry): + print "SalomeOutsideGUI.Display: not available outside GUI" + pass + + def DisplayOnly(self, Entry): + print "SalomeOutsideGUI.DisplayOnly: not available outside GUI" + pass + + def Erase(self, Entry): + print "SalomeOutsideGUI.Erase: not available outside GUI" + pass + + def DisplayAll(self): + print "SalomeOutsideGUI.Erase: not available outside GUI" + pass + + def EraseAll(self): + print "SalomeOutsideGUI.EraseAll: not available outside GUI" + pass + + def IsInCurrentView(self, Entry): + print "SalomeOutsideGUI.IsIncurentView: not available outside GUI" + return false + + def getComponentName(self, ComponentUserName ): + print "SalomeOutsideGUI.getComponentName: not available outside GUI" + return "" + + def getComponentUserName( self, ComponentName ): + print "SalomeOutsideGUI.getComponentUserName: not available outside GUI" + return "" + + #-------------------------------------------------------------------------- + + +def salome_iapp_init(embedded): global salome_iapp_initial global sg,IN_SALOME_GUI if salome_iapp_initial: salome_iapp_initial=0 - import libSALOME_Swig + if embedded: + import libSALOME_Swig - class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig): - getAllSelected = SalomeGUIgetAllSelected + class SalomeGUI(libSALOME_Swig.SALOMEGUI_Swig): + getAllSelected = SalomeGUIgetAllSelected - # create a SALOMEGUI_Swig instance - sg = SalomeGUI() - IN_SALOME_GUI = sg.hasDesktop() + # create a SALOMEGUI_Swig instance + sg = SalomeGUI() + IN_SALOME_GUI = sg.hasDesktop() + else: + # Not embedded in GUI + sg=SalomeOutsideGUI() + IN_SALOME_GUI=0 return sg diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index f643e844b..6855fe7f6 100644 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -245,11 +245,10 @@ def getActiveStudy(theStudyId=0): global salome_study_ID print "getActiveStudy" - sg = salome_iapp.salome_iapp_init() if salome_study_ID == -1: - if sg.hasDesktop(): + if salome_iapp.hasDesktop(): print "---in gui" - salome_study_ID = sg.getActiveStudyId() + salome_study_ID = salome_iapp.sg.getActiveStudyId() else: print "---outside gui" if theStudyId: -- 2.39.2