3 from omniORB import CORBA
5 # Import the stubs for the Naming service
8 # -----------------------------------------------------------------------------
11 XTERM="/usr/bin/X11/xterm -iconic -e "
15 commande=self.XTERM+self.CMD
17 ier=os.system(commande)
18 if ier:print "Commande failed"
20 # -----------------------------------------------------------------------------
22 class NamingServer(Server):
24 CMD="runNS.sh > /tmp/salomeNS.log 2>&1"
26 # -----------------------------------------------------------------------------
32 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
33 # Initialise the Naming Service
36 # --------------------------------------------------------------------------
39 # Obtain a reference to the root naming context
40 obj = self.orb.resolve_initial_references("NameService")
42 self.rootContext = obj._narrow(CosNaming.NamingContext)
44 except CORBA.COMM_FAILURE:
45 self.rootContext = None
46 print "Lancement du Naming Service",
48 # On lance le Naming Server (doit etre dans le PATH)
50 print "Searching Naming Service ",
56 obj = self.orb.resolve_initial_references("NameService")
57 self.rootContext = obj._narrow(CosNaming.NamingContext)
59 except (CORBA.COMM_FAILURE,CORBA.OBJECT_NOT_EXIST):
60 self.rootContext = None
65 if self.rootContext is None:
66 print "Failed to narrow the root naming context"
68 print " found in %s seconds " % ((ncount-1)*delta)
70 # --------------------------------------------------------------------------
72 def showNScontext(self,context,dec=''):
76 for s in b.binding_name :
77 print "%s%s.%s" %(dec,s.id,s.kind)
79 obj=context.resolve([s])
80 scontext = obj._narrow(CosNaming.NamingContext)
81 self.showNScontext(scontext,dec=dec+' ')
84 # --------------------------------------------------------------------------
87 """ Show the content of NS"""
88 self.showNScontext(self.rootContext)
90 # --------------------------------------------------------------------------
92 def Resolve(self, Path):
93 resolve_path=string.split(Path,'/')
94 if resolve_path[0] == '': del resolve_path[0]
95 dir_path=resolve_path[:-1]
98 context_name.append(CosNaming.NameComponent(e,"dir"))
99 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
102 obj = self.rootContext.resolve(context_name)
103 except CosNaming.NamingContext.NotFound, ex:
105 except CosNaming.NamingContext.InvalidName, ex:
107 except CosNaming.NamingContext.CannotProceed, ex:
109 except CORBA.COMM_FAILURE, ex:
113 # --------------------------------------------------------------------------
115 def waitNS(self,name,typobj=None,maxcount=70):
118 print "Searching %s in Naming Service " % name,
121 if count > maxcount : raise "Impossible de trouver %s" % name
122 obj=self.Resolve(name)
124 print " found in %s seconds " % ((count-1)*delta)
127 sys.stdout.write('+')
131 if typobj is None:return obj
133 nobj = obj._narrow(typobj)
135 print "%s exists but is not a %s" % (name,typobj)
138 # --------------------------------------------------------------------------
140 def ResolveLogger(self, name):
142 context_name.append(CosNaming.NameComponent(name,""))
145 obj = self.rootContext.resolve(context_name)
146 except CosNaming.NamingContext.NotFound, ex:
148 except CosNaming.NamingContext.InvalidName, ex:
150 except CosNaming.NamingContext.CannotProceed, ex:
152 except CORBA.COMM_FAILURE, ex:
156 # --------------------------------------------------------------------------
158 def waitLogger(self,name,typobj=None,maxcount=10):
161 print "Searching %s in Naming Service " % name,
164 if count > maxcount : raise "Impossible de trouver %s" % name
165 obj=self.ResolveLogger(name)
167 print " found in %s seconds " % ((count-1)*delta)
170 sys.stdout.write('+')
174 if typobj is None:return obj
176 nobj = obj._narrow(typobj)
178 print "%s exists but is not a %s" % (name,typobj)