1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # \brief Module that provides a client for %SALOME
30 from nameserver import *
31 from omniORB import CORBA
32 from launchConfigureParser import verbose
34 # Import the stubs for the Naming service
37 # -----------------------------------------------------------------------------
40 """Client for SALOME"""
42 def __init__(self,args=None):
44 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
46 # Initialise the Naming Service
47 self.initNS(args or {})
49 # --------------------------------------------------------------------------
51 def initNS(self,args):
52 # Obtain a reference to the root naming context
53 obj = self.orb.resolve_initial_references("NameService")
55 self.rootContext = obj._narrow(CosNaming.NamingContext)
57 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
58 self.rootContext = None
59 if verbose(): print "Launch Naming Service++",
61 # On lance le Naming Server (doit etre dans le PATH)
63 if args['wake_up_session']:
67 NamingServer(args).run()
69 print "Searching Naming Service ",
75 obj = self.orb.resolve_initial_references("NameService")
76 self.rootContext = obj._narrow(CosNaming.NamingContext)
78 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
79 self.rootContext = None
84 if self.rootContext is None:
85 print "Failed to narrow the root naming context"
87 print " found in %s seconds " % ((ncount-1)*delta)
89 # --------------------------------------------------------------------------
91 def showNScontext(self,context,dec=''):
96 for s in b.binding_name :
97 print "%s%s.%s" %(dec,s.id,s.kind)
99 obj=context.resolve([s])
100 scontext = obj._narrow(CosNaming.NamingContext)
101 self.showNScontext(scontext,dec=dec+' ')
104 # --------------------------------------------------------------------------
107 """ Show the content of SALOME naming service """
108 self.showNScontext(self.rootContext)
110 # --------------------------------------------------------------------------
112 def Resolve(self, Path):
113 resolve_path=string.split(Path,'/')
114 if resolve_path[0] == '': del resolve_path[0]
115 dir_path=resolve_path[:-1]
118 context_name.append(CosNaming.NameComponent(e,"dir"))
119 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
122 obj = self.rootContext.resolve(context_name)
123 except CosNaming.NamingContext.NotFound, ex:
125 except CosNaming.NamingContext.InvalidName, ex:
127 except CosNaming.NamingContext.CannotProceed, ex:
129 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
133 # --------------------------------------------------------------------------
135 def waitNS(self,name,typobj=None,maxcount=240):
138 print "Searching %s in Naming Service " % name,
141 if count > maxcount : raise RuntimeError, "Impossible de trouver %s" % name
142 obj=self.Resolve(name)
144 print " found in %s seconds " % ((count-1)*delta)
147 sys.stdout.write('+')
151 if typobj is None:return obj
153 nobj = obj._narrow(typobj)
155 print "%s exists but is not a %s" % (name,typobj)
158 if sys.platform != "win32":
159 def waitNSPID(self, theName, thePID, theTypObj = None):
163 print "Searching %s in Naming Service " % theName,
168 raise RuntimeError, "Process %d for %s not found" % (thePID,theName)
170 anObj = self.Resolve(theName)
172 print " found in %s seconds " % ((aCount-1)*aDelta)
175 sys.stdout.write('+')
181 if theTypObj is None:
184 anObject = anObj._narrow(theTypObj)
186 print "%s exists but is not a %s" % (theName,theTypObj)
190 # --------------------------------------------------------------------------
192 def ResolveLogger(self, name):
194 context_name.append(CosNaming.NameComponent(name,""))
197 obj = self.rootContext.resolve(context_name)
198 except CosNaming.NamingContext.NotFound, ex:
200 except CosNaming.NamingContext.InvalidName, ex:
202 except CosNaming.NamingContext.CannotProceed, ex:
204 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
208 # --------------------------------------------------------------------------
210 def waitLogger(self,name,typobj=None,maxcount=40):
213 print "Searching %s in Naming Service " % name,
216 if count > maxcount : raise RuntimeError, "Impossible de trouver %s" % name
217 obj=self.ResolveLogger(name)
219 print " found in %s seconds " % ((count-1)*delta)
222 sys.stdout.write('+')
226 if typobj is None:return obj
228 nobj = obj._narrow(typobj)
230 print "%s exists but is not a %s" % (name,typobj)