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.TRANSIENT,CORBA.OBJECT_NOT_EXIST,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.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
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=''):
83 for s in b.binding_name :
84 print "%s%s.%s" %(dec,s.id,s.kind)
86 obj=context.resolve([s])
87 scontext = obj._narrow(CosNaming.NamingContext)
88 self.showNScontext(scontext,dec=dec+' ')
91 # --------------------------------------------------------------------------
94 """ Show the content of NS"""
95 self.showNScontext(self.rootContext)
97 # --------------------------------------------------------------------------
99 def Resolve(self, Path):
100 resolve_path=string.split(Path,'/')
101 if resolve_path[0] == '': del resolve_path[0]
102 dir_path=resolve_path[:-1]
105 context_name.append(CosNaming.NameComponent(e,"dir"))
106 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
109 obj = self.rootContext.resolve(context_name)
110 except CosNaming.NamingContext.NotFound, ex:
112 except CosNaming.NamingContext.InvalidName, ex:
114 except CosNaming.NamingContext.CannotProceed, ex:
116 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
120 # --------------------------------------------------------------------------
122 def waitNS(self,name,typobj=None,maxcount=60):
125 print "Searching %s in Naming Service " % name,
128 if count > maxcount : raise "Impossible de trouver %s" % name
129 obj=self.Resolve(name)
131 print " found in %s seconds " % ((count-1)*delta)
134 sys.stdout.write('+')
138 if typobj is None:return obj
140 nobj = obj._narrow(typobj)
142 print "%s exists but is not a %s" % (name,typobj)
145 # --------------------------------------------------------------------------
147 def ResolveLogger(self, name):
149 context_name.append(CosNaming.NameComponent(name,""))
152 obj = self.rootContext.resolve(context_name)
153 except CosNaming.NamingContext.NotFound, ex:
155 except CosNaming.NamingContext.InvalidName, ex:
157 except CosNaming.NamingContext.CannotProceed, ex:
159 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
163 # --------------------------------------------------------------------------
165 def waitLogger(self,name,typobj=None,maxcount=40):
168 print "Searching %s in Naming Service " % name,
171 if count > maxcount : raise "Impossible de trouver %s" % name
172 obj=self.ResolveLogger(name)
174 print " found in %s seconds " % ((count-1)*delta)
177 sys.stdout.write('+')
181 if typobj is None:return obj
183 nobj = obj._narrow(typobj)
185 print "%s exists but is not a %s" % (name,typobj)