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