1 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from omniORB import CORBA
23 # Import the stubs for the Naming service
26 # -----------------------------------------------------------------------------
29 XTERM="/usr/bin/X11/xterm -iconic -e "
33 commande=self.XTERM+self.CMD
35 ier=os.system(commande)
36 if ier:print "Commande failed"
38 # -----------------------------------------------------------------------------
40 class NamingServer(Server):
42 USER=os.getenv('USER')
45 os.system("mkdir -m 777 -p /tmp/logs")
46 LOGDIR="/tmp/logs/" + USER
47 os.system("mkdir -m 777 -p " + LOGDIR)
48 CMD="runNS.sh > " + LOGDIR + "/salomeNS.log 2>&1"
50 # -----------------------------------------------------------------------------
56 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
57 # Initialise the Naming Service
60 # --------------------------------------------------------------------------
63 # Obtain a reference to the root naming context
64 obj = self.orb.resolve_initial_references("NameService")
66 self.rootContext = obj._narrow(CosNaming.NamingContext)
68 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
69 self.rootContext = None
70 print "Lancement du Naming Service",
72 # On lance le Naming Server (doit etre dans le PATH)
74 print "Searching Naming Service ",
80 obj = self.orb.resolve_initial_references("NameService")
81 self.rootContext = obj._narrow(CosNaming.NamingContext)
83 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
84 self.rootContext = None
89 if self.rootContext is None:
90 print "Failed to narrow the root naming context"
92 print " found in %s seconds " % ((ncount-1)*delta)
94 # --------------------------------------------------------------------------
96 def showNScontext(self,context,dec=''):
101 for s in b.binding_name :
102 print "%s%s.%s" %(dec,s.id,s.kind)
104 obj=context.resolve([s])
105 scontext = obj._narrow(CosNaming.NamingContext)
106 self.showNScontext(scontext,dec=dec+' ')
109 # --------------------------------------------------------------------------
112 """ Show the content of NS"""
113 self.showNScontext(self.rootContext)
115 # --------------------------------------------------------------------------
117 def Resolve(self, Path):
118 resolve_path=string.split(Path,'/')
119 if resolve_path[0] == '': del resolve_path[0]
120 dir_path=resolve_path[:-1]
123 context_name.append(CosNaming.NameComponent(e,"dir"))
124 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
127 obj = self.rootContext.resolve(context_name)
128 except CosNaming.NamingContext.NotFound, ex:
130 except CosNaming.NamingContext.InvalidName, ex:
132 except CosNaming.NamingContext.CannotProceed, ex:
134 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
138 # --------------------------------------------------------------------------
140 def waitNS(self,name,typobj=None,maxcount=60):
143 print "Searching %s in Naming Service " % name,
146 if count > maxcount : raise "Impossible de trouver %s" % name
147 obj=self.Resolve(name)
149 print " found in %s seconds " % ((count-1)*delta)
152 sys.stdout.write('+')
156 if typobj is None:return obj
158 nobj = obj._narrow(typobj)
160 print "%s exists but is not a %s" % (name,typobj)
162 def waitNSPID(self, theName, thePID, theTypObj = None):
166 print "Searching %s in Naming Service " % theName,
169 aPid, aStatus = os.waitpid(thePID,os.WNOHANG)
170 except Exception, exc:
171 raise "Impossible de trouver %s" % theName
173 anObj = self.Resolve(theName)
175 print " found in %s seconds " % ((aCount-1)*aDelta)
178 sys.stdout.write('+')
184 if theTypObj is None:
187 anObject = anObj._narrow(theTypObj)
189 print "%s exists but is not a %s" % (theName,theTypObj)
193 # --------------------------------------------------------------------------
195 def ResolveLogger(self, name):
197 context_name.append(CosNaming.NameComponent(name,""))
200 obj = self.rootContext.resolve(context_name)
201 except CosNaming.NamingContext.NotFound, ex:
203 except CosNaming.NamingContext.InvalidName, ex:
205 except CosNaming.NamingContext.CannotProceed, ex:
207 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
211 # --------------------------------------------------------------------------
213 def waitLogger(self,name,typobj=None,maxcount=40):
216 print "Searching %s in Naming Service " % name,
219 if count > maxcount : raise "Impossible de trouver %s" % name
220 obj=self.ResolveLogger(name)
222 print " found in %s seconds " % ((count-1)*delta)
225 sys.stdout.write('+')
229 if typobj is None:return obj
231 nobj = obj._narrow(typobj)
233 print "%s exists but is not a %s" % (name,typobj)