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 USER=os.getenv('USER')
27 LOGDIR="/tmp/logs/" + USER
28 os.system("mkdir -m 777 -p " + LOGDIR)
29 CMD="runNS.sh > " + LOGDIR + "/salomeNS.log 2>&1"
31 # -----------------------------------------------------------------------------
37 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
38 # Initialise the Naming Service
41 # --------------------------------------------------------------------------
44 # Obtain a reference to the root naming context
45 obj = self.orb.resolve_initial_references("NameService")
47 self.rootContext = obj._narrow(CosNaming.NamingContext)
49 except CORBA.COMM_FAILURE:
50 self.rootContext = None
51 print "Lancement du Naming Service",
53 # On lance le Naming Server (doit etre dans le PATH)
55 print "Searching Naming Service ",
61 obj = self.orb.resolve_initial_references("NameService")
62 self.rootContext = obj._narrow(CosNaming.NamingContext)
64 except (CORBA.COMM_FAILURE,CORBA.OBJECT_NOT_EXIST):
65 self.rootContext = None
70 if self.rootContext is None:
71 print "Failed to narrow the root naming context"
73 print " found in %s seconds " % ((ncount-1)*delta)
75 # --------------------------------------------------------------------------
77 def showNScontext(self,context,dec=''):
81 for s in b.binding_name :
82 print "%s%s.%s" %(dec,s.id,s.kind)
84 obj=context.resolve([s])
85 scontext = obj._narrow(CosNaming.NamingContext)
86 self.showNScontext(scontext,dec=dec+' ')
89 # --------------------------------------------------------------------------
92 """ Show the content of NS"""
93 self.showNScontext(self.rootContext)
95 # --------------------------------------------------------------------------
97 def Resolve(self, Path):
98 resolve_path=string.split(Path,'/')
99 if resolve_path[0] == '': del resolve_path[0]
100 dir_path=resolve_path[:-1]
103 context_name.append(CosNaming.NameComponent(e,"dir"))
104 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
107 obj = self.rootContext.resolve(context_name)
108 except CosNaming.NamingContext.NotFound, ex:
110 except CosNaming.NamingContext.InvalidName, ex:
112 except CosNaming.NamingContext.CannotProceed, ex:
114 except CORBA.COMM_FAILURE, ex:
118 # --------------------------------------------------------------------------
120 def waitNS(self,name,typobj=None,maxcount=70):
123 print "Searching %s in Naming Service " % name,
126 if count > maxcount : raise "Impossible de trouver %s" % name
127 obj=self.Resolve(name)
129 print " found in %s seconds " % ((count-1)*delta)
132 sys.stdout.write('+')
136 if typobj is None:return obj
138 nobj = obj._narrow(typobj)
140 print "%s exists but is not a %s" % (name,typobj)
143 # --------------------------------------------------------------------------
145 def ResolveLogger(self, name):
147 context_name.append(CosNaming.NameComponent(name,""))
150 obj = self.rootContext.resolve(context_name)
151 except CosNaming.NamingContext.NotFound, ex:
153 except CosNaming.NamingContext.InvalidName, ex:
155 except CosNaming.NamingContext.CannotProceed, ex:
157 except CORBA.COMM_FAILURE, ex:
161 # --------------------------------------------------------------------------
163 def waitLogger(self,name,typobj=None,maxcount=10):
166 print "Searching %s in Naming Service " % name,
169 if count > maxcount : raise "Impossible de trouver %s" % name
170 obj=self.ResolveLogger(name)
172 print " found in %s seconds " % ((count-1)*delta)
175 sys.stdout.write('+')
179 if typobj is None:return obj
181 nobj = obj._narrow(typobj)
183 print "%s exists but is not a %s" % (name,typobj)