Salome HOME
Fix for "23677: [CEA 13186] cannot save study to h5 format" issue.
[modules/kernel.git] / bin / nameserver.py
1 #!/usr/bin/env python3
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24
25 import os, sys, re, socket
26 #import commands
27 from server import Server
28 from salome_utils import getHostName
29 from launchConfigureParser import verbose
30
31 # -----------------------------------------------------------------------------
32
33 class NamingServer(Server):
34     #XTERM = ""
35     #USER = os.getenv('USER')
36     #if USER is None:
37     #  USER = 'anonymous'
38     #os.system("mkdir -m 777 -p /tmp/logs")
39     #LOGDIR = "/tmp/logs/" + USER
40
41     def initNSArgs(self):
42         from salome_utils import getLogDir
43         upath = getLogDir()
44         try:
45             os.makedirs(upath, mode=0o777)
46         except:
47             pass
48
49         if verbose(): print("Name Service... ", end =' ')
50         hname = getHostName()
51
52         with open(os.environ["OMNIORB_CONFIG"]) as f:
53           ss = re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
54           if verbose(): print("ss = ", ss, end=' ')
55         sl = ss[0]
56         ll = sl.split(':')
57         aPort = ll[-1]
58         #aPort=(ss.join().split(':'))[2];
59         #aPort=re.findall("\d+", ss[0])[0]
60
61         # \begin{E.A.}
62         # put the log files of omniNames in different directory with port reference,
63         # it is cleaner on linux and it is a fix for salome since it is impossible to
64         # remove the log files if the corresponding omniNames has not been killed.
65         # \end{E.A.}
66
67         upath = os.path.join(upath, "omniNames_%s"%(aPort))
68         try:
69           os.mkdir(upath)
70         except:
71           # print("Can't create " + upath)
72           pass
73
74         #os.system("touch " + upath + "/dummy")
75         for fname in os.listdir(upath):
76           try:
77             os.remove(upath + "/" + fname)
78           except:
79             pass
80         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
81
82         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
83         # print("sed command = ", aSedCommand)
84         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
85         # print("port=", aPort)
86         if sys.platform == "win32":
87           # print("start omniNames -start " + aPort + " -logdir " + upath)
88           self.CMD = ['omniNames', '-start' , aPort , '-nohostname', '-logdir' , os.path.realpath(upath), '-errlog', os.path.realpath(os.path.join(upath,'omniNameErrors.log'))]
89           #os.system("start omniNames -start " + aPort + " -logdir " + upath)
90         else:
91           #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &']
92           self.CMD = ['omniNames','-start' , aPort, '-logdir' , upath, '-errlog', upath+'/omniNameErrors.log']
93           #os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
94
95         if verbose(): print("... ok")
96         if verbose(): print("to list contexts and objects bound into the context with the specified name : showNS ")
97
98
99     def initArgs(self):
100         Server.initArgs(self)
101         if sys.platform == "win32":
102           env_ld_library_path = ['env', 'LD_LIBRARY_PATH=' + os.getenv("PATH")]
103         elif sys.platform == "darwin":
104           env_ld_library_path = ['env', 'DYLD_LIBRARY_PATH=' + os.getenv("DYLD_LIBRARY_PATH"), 'DYLD_FALLBACK_LIBRARY_PATH=' + os.getenv("DYLD_FALLBACK_LIBRARY_PATH")]
105         else:
106           env_ld_library_path = ['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
107         self.CMD = ['xterm', '-e']+ env_ld_library_path + ['python']
108         self.initNSArgs()
109
110 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
111 #    computer if this Container does not exist. Default is localhost.
112 #    Others Containers are started with start_impl method of FactoryServer Container.
113 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
114 # Warning : on RedHat the file /etc/hosts contains by default a line like :
115 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
116 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
117 #   computers only if the computer name is removed on that line like :
118 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
119
120 # To start dynamically Containers on several computers you need to
121 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
122 # example : ORBInitRef NameService=corbaname::dm2s0017
123
124 # If you need to use several omniNames running on the same computer, you have to :
125 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
126 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
127 #2. start omninames with this port number like in orbmodile.py
128 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &