]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Management of :
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 23 Feb 2022 09:45:52 +0000 (10:45 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 24 Feb 2022 12:06:40 +0000 (13:06 +0100)
- salome -t <script.py>
- salome -l
- fix problem of KERNEL_UnitTest

bin/killSalomeWithPort.py
bin/runSalome.py
bin/runSalomeCommon.py
bin/salomeContext.py
src/Logger/SALOME_Logger_Server_main.cxx
src/Logger/SALOME_Trace.py
src/SALOMETraceCollector/CMakeLists.txt
src/SALOMETraceCollector/SALOMETraceCollector.cxx
src/Utils/Test/UtilsTest.cxx

index 5375452df8317cebcae2b9639e7902b7c21d9042..04e6939f6702a96ef1826388d28fcc9e82b62a4a 100755 (executable)
@@ -65,6 +65,8 @@ import psutil
 
 from salome_utils import (generateFileName, getHostName, getLogDir, getShortHostName,
                           getUserName, killOmniNames, killPid, verbose)
+import logging
+logger = logging.getLogger()
 
 def getPiDict(port, appname='salome', full=True, hidden=True, hostname=None):
     """
@@ -247,6 +249,7 @@ def __killPids(pids):
     processes = []
     for pid in pids:
         try:
+            logger.debug("Add process with PID = {} into PIDList to kill".format(pid))
             processes.append(psutil.Process(pid))
         except psutil.NoSuchProcess:
             if verbose():
@@ -262,7 +265,7 @@ def __killMyPort(port, filedict):
     # ensure port is an integer
     with suppress(ValueError):
         port = int(port)
-
+    logger.debug("Into __killMyPort with port {}. File containing PID to kill is {}".format(port,filedict))
     # read pids from pidict file
     with suppress(Exception), open(filedict, 'rb') as fpid:
         pids_lists = pickle.load(fpid)
index 20f3da436b1fa1d6a045127e41e817b75454255f..422631b68340130606e80482e768c60617c57061 100755 (executable)
@@ -80,6 +80,7 @@ def startSalome(args, modules_list, modules_root_dir):
         mySessionServ.setpath(modules_list,modules_root_dir)
         mySessionServ.run()
         ior_fakens_filename = mySessionServ.iorfakens
+        logger.debug("Rendez-vous file for to retrieve IOR of session is \"{}\"".format(ior_fakens_filename))
     
     end_time = os.times()
 
@@ -106,7 +107,7 @@ def startSalome(args, modules_list, modules_root_dir):
     logger.debug("additional external python interpreters: {}".format(nbaddi))
     if nbaddi:
         for i in range(nbaddi):
-            anInterp=InterpServer(args)
+            anInterp=runSalomeCommon.InterpServer(args)
             anInterp.run()
 
     # set PYTHONINSPECT variable (python interpreter in interactive mode)
@@ -174,7 +175,7 @@ def addToPidict(args):
     global process_id
     from addToKillList import addToKillList
     for pid, cmd in list(process_id.items()):
-        addToKillList(pid, cmd, args['port'])
+        addToKillList(pid, cmd)
 
 # -----------------------------------------------------------------------------
 
@@ -187,6 +188,26 @@ def main(exeName=None):
     # --
     setenv.set_env(args, modules_list, modules_root_dir, keepEnvironment=keep_env)
     ior_fakens_filename = useSalome(args, modules_list, modules_root_dir)
+    # Management of -t <script.py>
+    toimport = []
+    if 'gui' in args and 'session_gui' in args:
+        if not args['gui'] or not args['session_gui']:
+            if 'study_hdf' in args:
+                toopen = args['study_hdf']
+                if toopen:
+                    import salome
+                    salome.salome_init(path=toopen)
+            if 'pyscript' in args:
+                toimport = args['pyscript']
+    from salomeContextUtils import formatScriptsAndArgs
+    from addToKillList import addToKillList
+    command = formatScriptsAndArgs(toimport, escapeSpaces=True)
+    if command:
+        logger.debug("Launching following shell command : {}".format(str(command)))
+        proc = subprocess.Popen(command, shell=True)
+        addToKillList(proc.pid, command)
+        res = proc.wait()
+        if res: sys.exit(1) 
     return args, ior_fakens_filename
 
 # -----------------------------------------------------------------------------
@@ -273,12 +294,14 @@ def foreGround(args, ior_fakens_filename):
                 status = session.GetStatSession()
                 assert status.activeGUI
             except Exception:
+                logger.debug("Process of the session under monitoring {} has vanished !".format(session_pid))
                 break
             from time import sleep
             sleep(dt)
             pass
         pass
     except KeyboardInterrupt:
+        logger.debug("Keyboard requested : killing all process attached to port {}".format(port))
         from killSalomeWithPort import killMyPortSSL
         killMyPortSSL(port)
         pass
index 354017404be16e9cf52751a3dcb3d4ff699482c8..bbe117f7fda3d96da7c0ec100c30492613e6be5f 100755 (executable)
@@ -322,7 +322,6 @@ class CommonSessionServer(Server):
             pass
         if 'language' in self.args:
             self.SCMD2+=['--language=%s' % self.args['language']]
-        tempfile.mkstemp()
         os_handle, iorfakens = tempfile.mkstemp()
         self.iorfakens = iorfakens
         os.close(os_handle)
index 3cdc0c0a0a93299f1da20e5e864971a70ce30049..6687da1a40301c31b8a5c56d58f304c1dfb85ba9 100755 (executable)
@@ -367,7 +367,7 @@ class SalomeContext:
     sys.argv = ['runSalome'] + args
     import setenv
     setenv.main(True, exeName="salome withsession")
-    
+
     import runSalome
     runSalome.runSalome()
     return 0
index b2328f683739218ee95370b876ff300f5df911f5..a0b60b130290a2fe9d6eb6c1678b9f40f8d525b1 100644 (file)
@@ -32,6 +32,7 @@
 #include <SALOMEconfig.h>
 #include <sys/types.h>
 #include <stdlib.h>
+#include "KernelBasis.hxx"
 
 #ifndef WIN32
 # include <unistd.h>
@@ -61,7 +62,7 @@ int main(int argc, char **argv)
       CORBA::Object_var obj;
       PortableServer::POA_var poa;
       PortableServer::POAManager_var pman;   
-
+      setSSLMode(false);
       SetArgcArgv(argc, argv);
       CORBA::ORB_var orb = KERNEL::GetRefToORB() ;
 
index b9b5058c42be855a649da079e3e3e3a8a2b4258a..41e730241695af49aab2076459e6d867454a0691 100644 (file)
@@ -37,42 +37,60 @@ if ("SALOME_trace" in os.environ):
   if (os.environ["SALOME_trace"] == "with_logger"):
     trace="logger"
 
-class SALOME_Trace :
-    def __init__(self):
-        self.m_pInterfaceLogger = None
-        if trace=="logger":
-            ok = 0
-            steps = 40
-            while steps > 0 and ok == 0:
+def ReturnLoggerOld():
+      m_pInterfaceLogger = None
+      ok = 0
+      steps = 40
+      while steps > 0 and ok == 0:
+
+            try:
+                  orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
+                  theObj = orb.resolve_initial_references("NameService")
+                  inc = theObj._narrow(CosNaming.NamingContext)
+                  name = [CosNaming.NameComponent("Logger","")]
+                  obj = inc.resolve(name);
 
-              try:
-                orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
-                theObj = orb.resolve_initial_references("NameService")
-                inc = theObj._narrow(CosNaming.NamingContext)
-                name = [CosNaming.NameComponent("Logger","")]
-                obj = inc.resolve(name);
+                  m_pInterfaceLogger = obj._narrow(SALOME_Logger.Logger)
 
-                self.m_pInterfaceLogger = obj._narrow(SALOME_Logger.Logger)
+                  if not m_pInterfaceLogger is None:
+                        ok = 1
+            except CosNaming.NamingContext.NotFound as e :
+                  if steps == 1: print("Caught exception: Naming Service can't found Logger")
+            except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
+                  if steps == 1: print("Caught CORBA::SystemException CommFailure")
+            except CORBA.SystemException as e:
+                  if steps == 1: print("Caught CORBA::SystemException.")
+            except CORBA.Exception as e:
+                  if steps == 1: print("Caught CORBA::Exception.")
+            except Exception as e:
+                  if steps == 1: print("Caught unknown exception.")
 
-                if not self.m_pInterfaceLogger is None:
-                  ok = 1
+            time.sleep(0.25)
+            steps = steps - 1
+      return m_pInterfaceLogger
+      
+def ReturnLoggerSSL():
+      import KernelLogger
+      m_pInterfaceLogger = None
+      try:
+            m_pInterfaceLogger = KernelLogger.myLogger()
+      except Exception:
+            pass
+      return m_pInterfaceLogger
 
-              except CosNaming.NamingContext.NotFound as e :
-                    if steps == 1: print("Caught exception: Naming Service can't found Logger")
-              except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
-                    if steps == 1: print("Caught CORBA::SystemException CommFailure")
-              except CORBA.SystemException as e:
-                    if steps == 1: print("Caught CORBA::SystemException.")
-              except CORBA.Exception as e:
-                    if steps == 1: print("Caught CORBA::Exception.")
-              except Exception as e:
-                    if steps == 1: print("Caught unknown exception.")
+class SALOME_Trace :
+    def __init__(self):
+        self.m_pInterfaceLogger = None
+        if trace=="logger":
+            import KernelBasis
+            if KernelBasis.getSSLMode():
+                  self.m_pInterfaceLogger = ReturnLoggerSSL()
+            else:
+                  self.m_pInterfaceLogger = ReturnLoggerOld()
 
-              time.sleep(0.25)
-              steps = steps - 1
 
     def putMessage ( self, LogMsg ) :
         if (CORBA.is_nil(self.m_pInterfaceLogger)):
-            print(LogMsg);
+            print(LogMsg)
         else:
-            self.m_pInterfaceLogger.putMessage (LogMsg)
+            self.m_pInterfaceLogger.putMessage(LogMsg)
index b6bfd678be1df85cc85406156a44020656403a98..d7cdeab3ec60da8fdce3575e9281fc57645b48a4 100644 (file)
@@ -27,13 +27,14 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace
   ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
   ${CMAKE_CURRENT_SOURCE_DIR}/../NamingService
+  ${CMAKE_CURRENT_SOURCE_DIR}/../Logger
   ${PROJECT_BINARY_DIR}/idl
 )
 
 ADD_DEFINITIONS(${OMNIORB_DEFINITIONS} ${PTHREAD_DEFINITIONS})
 ADD_LIBRARY(with_loggerTraceCollector SALOMETraceCollector.cxx TraceCollector_WaitForServerReadiness.cxx)
 
-TARGET_LINK_LIBRARIES(with_loggerTraceCollector SalomeNS ArgvKeeper SALOMELocalTrace OpUtil SalomeIDLKernel ${OMNIORB_LIBRARIES} ${PTHREAD_LIBRARIES})
+TARGET_LINK_LIBRARIES(with_loggerTraceCollector SalomeNS ArgvKeeper SALOMELocalTrace SalomeLoggerServer OpUtil SalomeIDLKernel ${OMNIORB_LIBRARIES} ${PTHREAD_LIBRARIES})
 INSTALL(TARGETS with_loggerTraceCollector EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
 
 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
index 716cd598590a166bb9996a4f243dc474a558ff8d..82fdc3e67e9d56445eadec25868b6a2bf074f560 100644 (file)
@@ -209,11 +209,23 @@ SALOMETraceCollector::SALOMETraceCollector()
  */
 // ============================================================================
 
+#include "KernelBasis.hxx"
+#include "SALOME_Logger_Server.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+
+#include <memory>
+
 extern "C"
 {
  SALOMETRACECOLLECTOR_EXPORT
   BaseTraceCollector *SingletonInstance(void)
   {
+    if(getSSLMode())
+    {
+      SALOME_Logger::Logger_var logger = KERNEL::getLoggerServantSA();
+      std::unique_ptr<SALOME_Fake_NamingService> ns(new SALOME_Fake_NamingService);
+      ns->Register(logger,"/Logger");
+    }
     BaseTraceCollector *instance = SALOMETraceCollector::instance();
     return instance;
   }
index 2f14c1c0783785a473ea4f87405b1ae4f12647c8..8a3d1dab2eb1ec78b1223fd1b0d6d493efa982ae 100644 (file)
@@ -30,6 +30,7 @@
 #include "Basics_Utils.hxx"
 #include "Basics_DirUtils.hxx"
 #include "utilities.h"
+#include "KernelBasis.hxx"
 
 #ifdef WIN32
 #define setenv Kernel_Utils::setenv
@@ -53,6 +54,7 @@ UtilsTest::_getTraceFileName()
 void
 UtilsTest::setUp()
 {
+  setSSLMode(false);
   LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
   CPPUNIT_ASSERT(bp1);
   bp1->deleteInstance(bp1);