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 os.system("mkdir -m 777 -p /tmp/logs")
28 LOGDIR="/tmp/logs/" + USER
29 os.system("mkdir -m 777 -p " + LOGDIR)
30 CMD="runNS.sh > " + LOGDIR + "/salomeNS.log 2>&1"
32 # -----------------------------------------------------------------------------
38 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
39 # Initialise the Naming Service
42 # --------------------------------------------------------------------------
45 # Obtain a reference to the root naming context
46 obj = self.orb.resolve_initial_references("NameService")
48 self.rootContext = obj._narrow(CosNaming.NamingContext)
50 except CORBA.COMM_FAILURE:
51 self.rootContext = None
52 print "Lancement du Naming Service",
54 # On lance le Naming Server (doit etre dans le PATH)
56 print "Searching Naming Service ",
62 obj = self.orb.resolve_initial_references("NameService")
63 self.rootContext = obj._narrow(CosNaming.NamingContext)
65 except (CORBA.COMM_FAILURE,CORBA.OBJECT_NOT_EXIST):
66 self.rootContext = None
71 if self.rootContext is None:
72 print "Failed to narrow the root naming context"
74 print " found in %s seconds " % ((ncount-1)*delta)
76 # --------------------------------------------------------------------------
78 def showNScontext(self,context,dec=''):
82 for s in b.binding_name :
83 print "%s%s.%s" %(dec,s.id,s.kind)
85 obj=context.resolve([s])
86 scontext = obj._narrow(CosNaming.NamingContext)
87 self.showNScontext(scontext,dec=dec+' ')
90 # --------------------------------------------------------------------------
93 """ Show the content of NS"""
94 self.showNScontext(self.rootContext)
96 # --------------------------------------------------------------------------
98 def Resolve(self, Path):
99 resolve_path=string.split(Path,'/')
100 if resolve_path[0] == '': del resolve_path[0]
101 dir_path=resolve_path[:-1]
104 context_name.append(CosNaming.NameComponent(e,"dir"))
105 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
108 obj = self.rootContext.resolve(context_name)
109 except CosNaming.NamingContext.NotFound, ex:
111 except CosNaming.NamingContext.InvalidName, ex:
113 except CosNaming.NamingContext.CannotProceed, ex:
115 except CORBA.COMM_FAILURE, ex:
119 # --------------------------------------------------------------------------
121 def waitNS(self,name,typobj=None,maxcount=40):
124 print "Searching %s in Naming Service " % name,
127 if count > maxcount : raise "Impossible de trouver %s" % name
128 obj=self.Resolve(name)
130 print " found in %s seconds " % ((count-1)*delta)
133 sys.stdout.write('+')
137 if typobj is None:return obj
139 nobj = obj._narrow(typobj)
141 print "%s exists but is not a %s" % (name,typobj)
144 # --------------------------------------------------------------------------
146 def ResolveLogger(self, name):
148 context_name.append(CosNaming.NameComponent(name,""))
151 obj = self.rootContext.resolve(context_name)
152 except CosNaming.NamingContext.NotFound, ex:
154 except CosNaming.NamingContext.InvalidName, ex:
156 except CosNaming.NamingContext.CannotProceed, ex:
158 except CORBA.COMM_FAILURE, ex:
162 # --------------------------------------------------------------------------
164 def waitLogger(self,name,typobj=None,maxcount=40):
167 print "Searching %s in Naming Service " % name,
170 if count > maxcount : raise "Impossible de trouver %s" % name
171 obj=self.ResolveLogger(name)
173 print " found in %s seconds " % ((count-1)*delta)
176 sys.stdout.write('+')
180 if typobj is None:return obj
182 nobj = obj._narrow(typobj)
184 print "%s exists but is not a %s" % (name,typobj)