3 from nameserver import *
5 from omniORB import CORBA
7 # Import the stubs for the Naming service
11 # -----------------------------------------------------------------------------
15 def __init__(self,args):
17 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
18 # Initialise the Naming Service
21 # --------------------------------------------------------------------------
23 def initNS(self,args):
24 # Obtain a reference to the root naming context
25 obj = self.orb.resolve_initial_references("NameService")
27 self.rootContext = obj._narrow(CosNaming.NamingContext)
29 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
30 self.rootContext = None
31 print "Lancement du Naming Service",
33 # On lance le Naming Server (doit etre dans le PATH)
34 ns = NamingServer(args).run()
35 print "Searching Naming Service ",
41 obj = self.orb.resolve_initial_references("NameService")
42 self.rootContext = obj._narrow(CosNaming.NamingContext)
44 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
45 self.rootContext = None
50 if self.rootContext is None:
51 print "Failed to narrow the root naming context"
53 print " found in %s seconds " % ((ncount-1)*delta)
55 # --------------------------------------------------------------------------
57 def showNScontext(self,context,dec=''):
62 for s in b.binding_name :
63 print "%s%s.%s" %(dec,s.id,s.kind)
65 obj=context.resolve([s])
66 scontext = obj._narrow(CosNaming.NamingContext)
67 self.showNScontext(scontext,dec=dec+' ')
70 # --------------------------------------------------------------------------
73 """ Show the content of NS"""
74 self.showNScontext(self.rootContext)
76 # --------------------------------------------------------------------------
78 def Resolve(self, Path):
79 resolve_path=string.split(Path,'/')
80 if resolve_path[0] == '': del resolve_path[0]
81 dir_path=resolve_path[:-1]
84 context_name.append(CosNaming.NameComponent(e,"dir"))
85 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
88 obj = self.rootContext.resolve(context_name)
89 except CosNaming.NamingContext.NotFound, ex:
91 except CosNaming.NamingContext.InvalidName, ex:
93 except CosNaming.NamingContext.CannotProceed, ex:
95 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
99 # --------------------------------------------------------------------------
101 def waitNS(self,name,typobj=None,maxcount=1000):
104 print "Searching %s in Naming Service " % name,
107 if count > maxcount : raise "Impossible de trouver %s" % name
108 obj=self.Resolve(name)
110 print " found in %s seconds " % ((count-1)*delta)
113 sys.stdout.write('+')
117 if typobj is None:return obj
119 nobj = obj._narrow(typobj)
121 print "%s exists but is not a %s" % (name,typobj)
124 # --------------------------------------------------------------------------
126 if sys.platform != "win32":
127 def waitNSPID(self, theName, thePID, theTypObj = None):
131 print "Searching %s in Naming Service " % theName,
134 aPid, aStatus = os.waitpid(thePID,os.WNOHANG)
135 except Exception, exc:
136 raise "Impossible de trouver %s" % theName
138 anObj = self.Resolve(theName)
140 print " found in %s seconds " % ((aCount-1)*aDelta)
143 sys.stdout.write('+')
149 if theTypObj is None:
152 anObject = anObj._narrow(theTypObj)
154 print "%s exists but is not a %s" % (theName,theTypObj)
158 # --------------------------------------------------------------------------
160 def ResolveLogger(self, name):
162 context_name.append(CosNaming.NameComponent(name,""))
165 obj = self.rootContext.resolve(context_name)
166 except CosNaming.NamingContext.NotFound, ex:
168 except CosNaming.NamingContext.InvalidName, ex:
170 except CosNaming.NamingContext.CannotProceed, ex:
172 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
176 # --------------------------------------------------------------------------
178 def waitLogger(self,name,typobj=None,maxcount=40):
181 print "Searching %s in Naming Service " % name,
184 if count > maxcount : raise "Impossible de trouver %s" % name
185 obj=self.ResolveLogger(name)
187 print " found in %s seconds " % ((count-1)*delta)
190 sys.stdout.write('+')
194 if typobj is None:return obj
196 nobj = obj._narrow(typobj)
198 print "%s exists but is not a %s" % (name,typobj)