Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / bin / NSparam.py
1 #!/usr/bin/env python
2
3 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
4 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either 
8 # version 2.1 of the License.
9
10 # This library is distributed in the hope that it will be useful 
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public  
16 # License along with this library; if not, write to the Free Software 
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20
21
22 import sys,os
23 import string
24
25 def getNSparams(info=""):
26     """
27     check environment for omniORB configuration file.
28     parse the file to find the line defining naming service  host and port,
29     set environment variables NSPORT and NSHOST,
30     get host and port,
31     if   info==host print host
32     elif info==port print host
33     else    print 2 strings on stdout on one line: host port
34     """
35     my_port=""
36     my_host=""
37     if os.environ.has_key("OMNIORB_CONFIG"):
38         file = open(os.environ["OMNIORB_CONFIG"], "r")
39         s = file.read()
40         while len(s):
41             l = string.split(s, ":")
42             if string.split(l[0], " ")[0] == "ORBInitRef" or \
43                string.split(l[0], " ")[0] == "InitRef" :
44                 my_port = l[len(l)-1]
45                 if my_port[-1] == '\n':
46                     my_port = my_port[:-1]
47                     pass
48                 my_host = l[len(l)-2]
49                 break;
50                 pass
51             s = file.read()
52             pass
53         pass
54     if info=='host':
55         # keep print, stdout used in shell
56         print my_host
57         os.environ['NSHOST']=my_host
58         return my_host
59         pass
60     elif info=='port':
61         # keep print, stdout used in shell
62         print my_port
63         os.environ['NSPORT']=my_port
64         return my_port
65         pass
66     else:
67         # keep print, stdout used in shell
68         print  my_host, my_port
69         return my_host, my_port
70     pass
71
72 # ------------------------------------------------------------------------
73
74 if __name__ == "__main__":
75     if len(sys.argv) >1:        
76         if sys.argv[1]=='host':
77             getNSparams('host')
78             pass
79         elif sys.argv[1]=='port':
80             getNSparams('port')
81             pass
82         else:
83             getNSparams('')
84             pass
85         pass
86     else:
87         getNSparams('')
88         pass