Salome HOME
venv directory is configured in config_appli.xml file
[modules/kernel.git] / src / NamingService / SALOME_NamingServicePy.py
index 7ca7f90fdbbb5b5b27db56aad2a105cc4802a58c..00360abd002ce31d6cc121e846b3c3ef5cac7902 100644 (file)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -40,7 +40,7 @@ from string import *
 from SALOME_utilities import *
 #=============================================================================
 
-class SALOME_NamingServicePy_i(object):
+class SALOME_NamingServicePy_i:
     """
       A class to manage SALOME naming service from python code
     """
@@ -51,7 +51,7 @@ class SALOME_NamingServicePy_i(object):
     
     #-------------------------------------------------------------------------
 
-    def __init__(self, orb=None):
+    def __init__(self, orb=None, steps=240, spy=False):
         """
         Standard Constructor, with ORB reference.
  
@@ -63,7 +63,6 @@ class SALOME_NamingServicePy_i(object):
         self._orb = orb
         # initialize root context and current context
         ok = 0
-        steps = 240
         while steps > 0 and ok == 0:
           try:
             obj =self._orb.resolve_initial_references("NameService")
@@ -83,7 +82,10 @@ class SALOME_NamingServicePy_i(object):
           steps = steps - 1
         if steps == 0 and self._root_context is None: 
           MESSAGE ( "Name Service Reference is invalid" )
-          sys.exit(1)
+          if spy:
+            raise ValueError("Name Service Reference is invalid")
+          else:
+            sys.exit(1)
 
     #-------------------------------------------------------------------------
 
@@ -190,6 +192,43 @@ class SALOME_NamingServicePy_i(object):
             self._obj = None
         return self._obj
 
+    #-------------------------------------------------------------------------
+
+    def Resolve_Dir(self, Path):
+        """ ns.Resolve_Dir(pathname) -> dir
+
+        find a CORBA object (ior) by its pathname
+        """
+        #MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
+        path_list = list(Path)
+        if path_list[0]=='/':
+            self._current_context = self._root_context
+            #delete first '/' before split
+            Path=Path[1:]
+
+        result_resolve_path = Path.split('/')
+        _context_name=[]
+        for i in range(len(result_resolve_path)-1):
+            _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
+        _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"dir"))
+        print(_context_name)
+        return None
+        try:
+            self._obj = self._current_context.resolve(_context_name)
+        except CosNaming.NamingContext.NotFound as ex:
+            MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
+            self._obj = None
+        except CosNaming.NamingContext.InvalidName as ex:
+            MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
+            self._obj = None
+        except CosNaming.NamingContext.CannotProceed as ex:
+            MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
+            self._obj = None
+        except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
+            MESSAGE ( "Resolve : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
+            self._obj = None
+        return self._obj
+
 
     #-------------------------------------------------------------------------