Salome HOME
Bug IPAL19893 4.x: debug information is in terminal.
[modules/kernel.git] / bin / nameserver.py
1 #!/usr/bin/env python
2
3 import sys, os, re, socket
4 #import commands
5 from server import *
6 from Utils_Identity import getShortHostName
7 from launchConfigureParser import verbose
8
9 # -----------------------------------------------------------------------------
10
11 class NamingServer(Server):
12    XTERM=""
13    USER=os.getenv('USER')
14    if USER is None:
15       USER='anonymous'
16    #os.system("mkdir -m 777 -p /tmp/logs")
17    LOGDIR="/tmp/logs/" + USER
18
19    def initNSArgs(self):
20         if sys.platform == "win32":
21           # temporarily using home directory for Namning Service logs
22           # to be replaced with TEMP later...
23           os.environ["BaseDir"]=os.environ["HOME"]
24         else:
25           os.environ["BaseDir"]="/tmp"
26
27         try:
28           os.mkdir(os.environ["BaseDir"] + "/logs")
29           os.chmod(os.environ["BaseDir"] + "/logs", 0777)
30         except:
31           #print "Can't create " + os.environ["BaseDir"] + "/logs"
32           pass
33
34         upath = os.environ["BaseDir"] + "/logs/";
35         if sys.platform == "win32":
36            upath += os.environ["Username"];
37         else:
38            upath += os.environ["USER"];
39
40         try:
41           os.mkdir(upath)
42         except:
43           #print "Can't create " + upath
44           pass
45
46         #os.system("touch " + upath + "/dummy")
47         for fname in os.listdir(upath):
48           try:
49             if not fname.startswith("."): os.remove(upath + "/" + fname)
50           except:
51             pass
52         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
53
54         if verbose(): print "Name Service... ",
55         #hname=os.environ["HOST"] #commands.getoutput("hostname")
56         if sys.platform == "win32":
57           hname=getShortHostName();
58         else:
59           hname = socket.gethostname();
60         #print "hname=",hname
61
62         f=open(os.environ["OMNIORB_CONFIG"])
63         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
64         if verbose(): print "ss = ", ss,
65         f.close()
66         sl=ss[0]
67         ll = sl.split(':')
68         aPort = ll[-1]
69         #aPort=(ss.join().split(':'))[2];
70         #aPort=re.findall("\d+", ss[0])[0]
71
72         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
73         #print "sed command = ", aSedCommand
74         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
75         #print "port=", aPort
76         if sys.platform == "win32":
77           #print "start omniNames -start " + aPort + " -logdir " + upath
78           self.CMD=['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"', ' -errlog', upath+'/omniNameErrors.log']
79           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
80         else:
81           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
82           self.CMD=['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
83           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
84
85         if verbose(): print "... ok"
86         if verbose(): print "to list contexts and objects bound into the context with the specified name : showNS "
87
88
89    def initArgs(self):
90         Server.initArgs(self)
91         if sys.platform == "win32":
92           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
93         else:
94           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
95         self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
96         self.initNSArgs()
97
98 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
99 #    computer if this Container does not exist. Default is localhost.
100 #    Others Containers are started with start_impl method of FactoryServer Container.
101 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
102 # Warning : on RedHat the file /etc/hosts contains by default a line like :
103 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
104 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
105 #   computers only if the computer name is removed on that line like :
106 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
107
108 # To start dynamically Containers on several computers you need to
109 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
110 # example : ORBInitRef NameService=corbaname::dm2s0017
111
112 # If you need to use several omniNames running on the same computer, you have to :
113 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
114 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
115 #2. start omninames with this port number like in orbmodile.py
116 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &