Back to index

salome-kernel  6.5.0
Public Member Functions | Static Private Attributes
SALOME_NamingServicePy.SALOME_NamingServicePy_i Class Reference

List of all members.

Public Member Functions

def __init__
def Register
def Resolve
def Create_Directory
def Destroy_Name
def Destroy_FullDirectory

Static Private Attributes

 _orb = None
 _root_context = None
 _current_context = None
 _obj = None

Detailed Description

  A class to manage SALOME naming service from python code

Definition at line 43 of file SALOME_NamingServicePy.py.


Constructor & Destructor Documentation

Standard Constructor, with ORB reference.
 
Initializes the naming service root context

Definition at line 54 of file SALOME_NamingServicePy.py.

00054 
00055     def __init__(self, orb=None):
00056         """
00057         Standard Constructor, with ORB reference.
00058  
00059         Initializes the naming service root context
00060         """
00061         #MESSAGE ( "SALOME_NamingServicePy_i::__init__" )
00062         if orb is None:
00063           orb=CORBA.ORB_init([''], CORBA.ORB_ID)
00064         self._orb = orb
00065         # initialize root context and current context
00066         ok = 0
00067         steps = 240
00068         while steps > 0 and ok == 0:
00069           try:
00070             obj =self._orb.resolve_initial_references("NameService")
00071             self._root_context =obj._narrow(CosNaming.NamingContext)
00072             self._current_context = self._root_context
00073 
00074         
00075             if self._root_context is None :
00076               #MESSAGE ( "Name Service Reference is invalid" )
00077               #sys.exit(1)
00078               MESSAGE(" Name service not found")
00079             else:
00080               ok = 1
00081           except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00082             MESSAGE(" Name service not found")
00083           time.sleep(0.25)
00084           steps = steps - 1
00085         if steps == 0 and self._root_context is None: 
00086           MESSAGE ( "Name Service Reference is invalid" )
00087           sys.exit(1)


Member Function Documentation

ns.Create_Directory(ObjRef, Path) 

create a sub directory 

Definition at line 196 of file SALOME_NamingServicePy.py.

00196 
00197     def Create_Directory(self,ObjRef, Path):
00198         """ ns.Create_Directory(ObjRef, Path) 
00199 
00200         create a sub directory 
00201         """
00202         MESSAGE ( "SALOME_NamingServicePy_i::Create_Directory" )
00203         _not_exist = 0
00204         path_list = list(Path)
00205         if path_list[0]=='/':
00206             self._current_context = self._root_context
00207             #delete first '/' before split
00208             Path=Path[1:]
00209 
00210         result_resolve_path = string.split(Path,'/')
00211         _context_name = []
00212         for i in range(len(result_resolve_path)):
00213             _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]            
00214             try:
00215                 obj = self._current_context.resolve(_context_name)
00216                 self._current_context = obj._narrow(CosNaming.NamingContext)
00217             except CosNaming.NamingContext.NotFound, ex:
00218                 self._current_context = self._current_context.bind_new_context(_context_name)
00219             except CosNaming.NamingContext.InvalidName, ex:
00220                 MESSAGE ( "Create_Directory : CosNaming.NamingContext.InvalidName" )
00221             except CosNaming.NamingContext.CannotProceed, ex:
00222                 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
00223             except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00224                 MESSAGE ( "Create_Directory : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
 
ns.Destroy_FullDirectory(Path)

  remove recursively a directory

Definition at line 245 of file SALOME_NamingServicePy.py.

00245 
00246     def Destroy_FullDirectory(self,Path):
00247       """ ns.Destroy_FullDirectory(Path)
00248 
00249         remove recursively a directory
00250       """
00251       context_name=[]
00252       for e in string.split(Path,'/'):
00253         if e == '':continue
00254         context_name.append(CosNaming.NameComponent(e,"dir"))
00255 
00256       try:
00257         context=self._root_context.resolve(context_name)
00258       except CosNaming.NamingContext.NotFound, ex:
00259         return
00260       except CORBA.Exception,ex:
00261         return
00262 
00263       bl,bi=context.list(0)
00264       if bi is not None:
00265          ok,b=bi.next_one()
00266          while(ok):
00267             for s in b.binding_name :
00268                if s.kind == "object":
00269                   context.unbind([s])
00270                elif s.kind == "dir":
00271                   context.unbind([s])
00272             ok,b=bi.next_one()
00273 
00274       context.destroy()
00275       self._root_context.unbind(context_name)
ns.Destroy_Name(Path) 

  remove a name in naming service

Definition at line 225 of file SALOME_NamingServicePy.py.

00225 
00226     def Destroy_Name(self,Path):
00227       """ ns.Destroy_Name(Path) 
00228 
00229         remove a name in naming service
00230       """
00231       resolve_path=string.split(Path,'/')
00232       if resolve_path[0] == '': del resolve_path[0]
00233       dir_path=resolve_path[:-1]
00234       context_name=[]
00235       for e in dir_path:
00236          context_name.append(CosNaming.NameComponent(e,"dir"))
00237       context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
00238       
00239       try:
00240         self._root_context.unbind(context_name)
00241       except CosNaming.NamingContext.NotFound, ex:
00242         return
00243       except CORBA.Exception,ex:
00244         return

def SALOME_NamingServicePy.SALOME_NamingServicePy_i.Register (   self,
  ObjRef,
  Path 
)
ns.Register(object,pathname )  

register a CORBA object under a pathname

Definition at line 90 of file SALOME_NamingServicePy.py.

00090 
00091     def Register(self,ObjRef, Path):
00092         """ ns.Register(object,pathname )  
00093         
00094         register a CORBA object under a pathname
00095         """
00096 
00097         MESSAGE ( "SALOME_NamingServicePy_i::Register" )
00098         _not_exist = 0
00099         path_list = list(Path)
00100         if path_list[0]=='/':
00101             self._current_context = self._root_context
00102             #delete first '/' before split
00103             Path=Path[1:]
00104 
00105         result_resolve_path = string.split(Path,'/')
00106         if len(result_resolve_path)>1:
00107             # A directory is treated (not only an object name)
00108             # We had to test if the directory where ObjRef should be recorded 
00109             # is already done
00110             # If not, the new context has to be created
00111             _context_name = []
00112             for i in range(len(result_resolve_path)-1):
00113                 _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
00114             
00115             try:
00116                 obj = self._current_context.resolve(_context_name)
00117                 self._current_context = obj._narrow(CosNaming.NamingContext)
00118             except CosNaming.NamingContext.NotFound, ex:
00119                 _not_exist = 1
00120             except CosNaming.NamingContext.InvalidName, ex:
00121                 MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
00122             except CosNaming.NamingContext.CannotProceed, ex:
00123                 MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
00124             except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00125                 MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
00126 
00127             if _not_exist:
00128                 # at least one context of the complete path is not created, we had
00129                 # to create it or them
00130                 _context_name = []
00131                 for i in range(len(result_resolve_path)-1):
00132                     _context_name = [CosNaming.NameComponent(result_resolve_path[i],"dir")]
00133 
00134                     try:
00135                         obj = self._current_context.resolve(_context_name)
00136                         self._current_context = obj._narrow(CosNaming.NamingContext)
00137                     except CosNaming.NamingContext.NotFound, ex:
00138                         #This context is not created. It will be done
00139                         self._current_context = self._current_context.bind_new_context(_context_name)
00140 
00141         #The current directory is now the directory where the object should 
00142         #be recorded
00143          
00144         _context_name = [CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")]
00145         try:
00146             self._current_context.bind(_context_name,ObjRef)
00147         except CosNaming.NamingContext.NotFound, ex:
00148             MESSAGE ( "Register : CosNaming.NamingContext.NotFound" )
00149         except CosNaming.NamingContext.InvalidName, ex:
00150             MESSAGE ( "Register : CosNaming.NamingContext.InvalidName" )
00151         except CosNaming.NamingContext.CannotProceed, ex:
00152             MESSAGE ( "Register : CosNaming.NamingContext.CannotProceed" )
00153         except CosNaming.NamingContext.AlreadyBound, ex:
00154             MESSAGE ( "Register : CosNaming.NamingContext.AlreadyBound, object will be rebind" )
00155             self._current_context.rebind(_context_name,ObjRef)
00156         except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00157             MESSAGE ( "Register : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )

ns.Resolve(pathname) -> object

find a CORBA object (ior) by its pathname

Definition at line 160 of file SALOME_NamingServicePy.py.

00160 
00161     def Resolve(self, Path):
00162         """ ns.Resolve(pathname) -> object
00163 
00164         find a CORBA object (ior) by its pathname
00165         """
00166         #MESSAGE ( "SALOME_NamingServicePy_i::Resolve" )
00167         path_list = list(Path)
00168         if path_list[0]=='/':
00169             self._current_context = self._root_context
00170             #delete first '/' before split
00171             Path=Path[1:]
00172 
00173         result_resolve_path = string.split(Path,'/')
00174         _context_name=[]
00175         for i in range(len(result_resolve_path)-1):
00176             _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
00177         _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object"))
00178         try:
00179             self._obj = self._current_context.resolve(_context_name)
00180         except CosNaming.NamingContext.NotFound, ex:
00181             MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" )
00182             self._obj = None
00183         except CosNaming.NamingContext.InvalidName, ex:
00184             MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" )
00185             self._obj = None
00186         except CosNaming.NamingContext.CannotProceed, ex:
00187             MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" )
00188             self._obj = None
00189         except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00190             MESSAGE ( "Resolve : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
00191             self._obj = None
00192         return self._obj
00193 


Member Data Documentation

Definition at line 49 of file SALOME_NamingServicePy.py.

Definition at line 50 of file SALOME_NamingServicePy.py.

Definition at line 47 of file SALOME_NamingServicePy.py.

Definition at line 48 of file SALOME_NamingServicePy.py.


The documentation for this class was generated from the following file: