Salome HOME
CCAR: some corrections in :
[modules/kernel.git] / src / NamingService / SALOME_NamingServicePy.py
index ab7f2050d1a6e8ab35a2cf71fba50aca1ceffd84..81ad8d15a94b01799eeb1f900daa6fbb29f4fc10 100644 (file)
@@ -19,7 +19,7 @@
 #  License along with this library; if not, write to the Free Software 
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 # 
-#  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 #
 #
@@ -32,12 +32,13 @@ import sys
 import time
 from omniORB import CORBA
 import CosNaming
+import string
 from string import *
 
 from SALOME_utilities import *
 #=============================================================================
 
-class SALOME_NamingServicePy_i:
+class SALOME_NamingServicePy_i(object):
     _orb = None
     _root_context=None
     _current_context=None
@@ -50,7 +51,7 @@ class SALOME_NamingServicePy_i:
         self._orb = orb
         # initialize root context and current context
        ok = 0
-       steps = 40
+       steps = 240
        while steps > 0 and ok == 0:
          try:
             obj =self._orb.resolve_initial_references("NameService")
@@ -68,11 +69,18 @@ class SALOME_NamingServicePy_i:
            MESSAGE(" Name service not found")
          time.sleep(0.25)
          steps = steps - 1
-        if steps == 0: 
+        if steps == 0 and self._root_context is None
           MESSAGE ( "Name Service Reference is invalid" )
           sys.exit(1)
+
     #-------------------------------------------------------------------------
+
     def Register(self,ObjRef, Path):
+        """ ns.Register(object,pathname )  
+        
+        register a CORBA object under a pathname
+        """
+
         MESSAGE ( "SALOME_NamingServicePy_i::Register" )
         _not_exist = 0
         path_list = list(Path)
@@ -81,7 +89,7 @@ class SALOME_NamingServicePy_i:
             #delete first '/' before split
             Path=Path[1:]
 
-        result_resolve_path = split(Path,'/')
+        result_resolve_path = string.split(Path,'/')
         if len(result_resolve_path)>1:
             # A directory is treated (not only an object name)
             # We had to test if the directory where ObjRef should be recorded 
@@ -135,9 +143,13 @@ class SALOME_NamingServicePy_i:
         except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
             MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
 
-            
     #-------------------------------------------------------------------------
+
     def Resolve(self, Path):
+        """ ns.Resolve(pathname) -> object
+
+        find a CORBA object (ior) by its pathname
+        """
         #MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
         path_list = list(Path)
         if path_list[0]=='/':
@@ -145,7 +157,7 @@ class SALOME_NamingServicePy_i:
             #delete first '/' before split
             Path=Path[1:]
 
-        result_resolve_path = split(Path,'/')
+        result_resolve_path = string.split(Path,'/')
         _context_name=[]
         for i in range(len(result_resolve_path)-1):
             _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
@@ -167,8 +179,8 @@ class SALOME_NamingServicePy_i:
         return self._obj
 
 
-
     #-------------------------------------------------------------------------
+
     def Create_Directory(self,ObjRef, Path):
         MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
         _not_exist = 0
@@ -178,7 +190,7 @@ class SALOME_NamingServicePy_i:
             #delete first '/' before split
             Path=Path[1:]
 
-        result_resolve_path = split(Path,'/')
+        result_resolve_path = string.split(Path,'/')
         _context_name = []
         for i in range(len(result_resolve_path)):
             _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]            
@@ -193,7 +205,46 @@ class SALOME_NamingServicePy_i:
                 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
             except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
                 MESSAGE ( "Create_Directory : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
-
  
-
-    
+    def Destroy_Name(self,Path):
+      resolve_path=string.split(Path,'/')
+      if resolve_path[0] == '': del resolve_path[0]
+      dir_path=resolve_path[:-1]
+      context_name=[]
+      for e in dir_path:
+         context_name.append(CosNaming.NameComponent(e,"dir"))
+      context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
+      
+      try:
+        self._root_context.unbind(context_name)
+      except CosNaming.NamingContext.NotFound, ex:
+        return
+      except CORBA.Exception,ex:
+        return
+
+    def Destroy_FullDirectory(self,Path):
+      context_name=[]
+      for e in string.split(Path,'/'):
+        if e == '':continue
+        context_name.append(CosNaming.NameComponent(e,"dir"))
+
+      try:
+        context=self._root_context.resolve(context_name)
+      except CosNaming.NamingContext.NotFound, ex:
+        return
+      except CORBA.Exception,ex:
+        return
+
+      bl,bi=context.list(0)
+      if bi is not None:
+         ok,b=bi.next_one()
+         while(ok):
+            for s in b.binding_name :
+               if s.kind == "object":
+                  context.unbind([s])
+               elif s.kind == "dir":
+                  context.unbind([s])
+            ok,b=bi.next_one()
+
+      context.destroy()
+      self._root_context.unbind(context_name)