Salome HOME
updated copyright message
[modules/kernel.git] / bin / ORBConfigFile.py
1 #!/usr/bin/env python3
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2023  CEA, EDF, 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 def readORBConfigFile(filename):
26   """ Extract information (host, port) from ORB configuration file. """
27   with open(filename) as f:
28     contents = f.readlines()
29
30   import re
31   host, port = None, None
32   for line in contents:
33     m = re.match("(ORB)?InitRef = NameService=corbaname::([\D\d]+):(\d*)", line)
34     if m:
35       host = m.group(2)
36       port = m.group(3)
37       break
38     pass
39   return host, port
40 #
41
42 def fillOrbConfigFileNoNS(prefix,orbdata):
43   GIOP_MaxMsgSize = 2097152000  # 2 GBytes
44   orbdata.append("%sgiopMaxMsgSize = %s # 2 GBytes"%(prefix,GIOP_MaxMsgSize))
45   orbdata.append("%straceLevel = 0 # critical errors only"%(prefix))
46   orbdata.append("%smaxGIOPConnectionPerServer = 500 # to allow containers parallel launch"%(prefix))
47   orbdata.append("%snativeCharCodeSet = UTF-8"%(prefix))
48   return GIOP_MaxMsgSize
49
50
51 def getPrefix():
52   from omniORB import CORBA
53   prefix = "" if CORBA.ORB_ID == "omniORB4" else "ORB"
54   return prefix
55   
56 def writeORBConfigFileSSL(path, kwargs={}):
57   from salome_utils import generateFileName
58   omniorb_config = generateFileName(path, prefix="omniORB",
59                                     extension="cfg",
60                                     hidden=True,
61                                     with_hostname=True,
62                                     **kwargs)
63   import os
64   os.environ['OMNIORB_CONFIG'] = omniorb_config
65   prefix = getPrefix()
66
67   orbdata = []
68   GIOP_MaxMsgSize = fillOrbConfigFileNoNS(prefix,orbdata)
69   orbdata.append("")
70
71   with open(omniorb_config, "w") as f:
72     f.write("\n".join(orbdata))
73     
74   return [ omniorb_config, GIOP_MaxMsgSize ]
75
76 # IMPORTANT NOTE: do not add any print call (cf. note at the bottom of the file)
77 def writeORBConfigFile(path, host, port, kwargs={}):
78
79   from salome_utils import generateFileName
80   omniorb_config = generateFileName(path, prefix="omniORB",
81                                     extension="cfg",
82                                     hidden=True,
83                                     with_hostname=True,
84                                     with_port=port,
85                                     **kwargs)
86   import os
87   os.environ['OMNIORB_CONFIG'] = omniorb_config
88   os.environ['NSPORT'] = "%s"%(port)
89   os.environ['NSHOST'] = "%s"%(host)
90
91   prefix = getPrefix()
92
93   orbdata = []
94   orbdata.append("%sInitRef = NameService=corbaname::%s:%s"%(prefix,host,port))
95   GIOP_MaxMsgSize = fillOrbConfigFileNoNS(prefix,orbdata)
96
97   orbdata.append("")
98
99   with open(omniorb_config, "w") as f:
100     f.write("\n".join(orbdata))
101
102   return [ omniorb_config, GIOP_MaxMsgSize ]
103
104 # -----------------------------------------------------------------------------
105
106 if __name__ == "__main__":
107   import sys
108   
109   if len(sys.argv) < 2:
110     sys.exit(-1)
111
112   path = sys.argv[1]
113   host = sys.argv[2]
114   port = sys.argv[3]
115   argv = sys.argv[4:]
116
117   kwargs = {}
118   for a in argv:
119     alist = str(a).split("=", 1)
120     opt = str(alist[0])
121     arg = alist[1]
122     kwargs[opt] = arg
123     pass
124
125   [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs)
126
127   # :TRICKY: print values so they can be read from caller bash script
128   # Example of bash script:
129   # RETURN_VALUES=$(python ORBConfigFile.py path host port)
130   # RETURN_VALUE_1=$(echo ${RETURN_VALUES} | cut -d' ' -f1)
131   # RETURN_VALUE_2=$(echo ${RETURN_VALUES} | cut -d' ' -f2)
132   # ...
133   # IMPORTANT NOTE: this print call MUST BE the first one!!
134   print(filename, msgSize)