]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
corrections for batch mode
authorprascle <prascle>
Tue, 28 Mar 2006 17:07:36 +0000 (17:07 +0000)
committerprascle <prascle>
Tue, 28 Mar 2006 17:07:36 +0000 (17:07 +0000)
bin/appliskel/runAppli
bin/appliskel/runConsole
bin/appliskel/runSession
bin/killSalomeWithPort.py
bin/salomeConsole.py
bin/salome_session.py [new file with mode: 0644]
src/KERNEL_PY/salome.py
src/KERNEL_PY/salome_iapp.py
src/KERNEL_PY/salome_study.py

index 1d86ad3d596273903687f570c706a0a420a8bf37..e28e9c9d420f15522535e29aea611b5be6415298 100755 (executable)
@@ -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)
index caeabbdd61319e13363aaad5944a21d032d5e8a9..c94a02fcf7988e68b18c96cdd1534aa530e70afe 100755 (executable)
@@ -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...)
 
index c0a26ba13399420f1f5ce5b9b1246293d7f8d779..69573bf10ec71d233e40e37c9e9ba2f673512471 100755 (executable)
@@ -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
index 9f0cd0dd9c9a317c94214935d2b23d9ef5bc7e88..bb1bec3b03db249396a74853fa8576ebdb68cf89 100755 (executable)
@@ -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\"")
index 5ce7cec640e869be3cb0c3df648a2baae2adbc12..9373022d235bcac4b6f282e911c3cc38d74db4e1 100755 (executable)
@@ -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 (file)
index 0000000..354bb33
--- /dev/null
@@ -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
index d853b2cb63d3df6754d7b808367ffcf3755f847b..f7e0099a4c1ea373f30c62d38ad6036b6c25a21a 100755 (executable)
@@ -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)
 
index e6ebcaf160733ff34107b4f2aa90d6c86598ec57..4752be1382937aff1b6c3e02bce20cb9941f57fc 100644 (file)
@@ -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
index f643e844be5aaeff08d2b0c5d05d50f14961dd1e..6855fe7f6d0d9b7e8697157f950219886657b634 100644 (file)
@@ -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: