#!/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...)
# --- 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)
#!/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...)
# 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...)
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
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\"")
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
--- /dev/null
+
+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
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
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)
#--------------------------------------------------------------------------
+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
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: