1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 from optparse import OptionParser
27 from NSparam import getNSparams
30 # Use to display newlines (\n) in epilog
31 class MyParser(OptionParser):
32 def format_epilog(self, formatter):
36 def configureSession(args=[]):
37 usage = "Usage: %prog [options] [command]"
39 If the command is not given a shell is opened; else execute the given command.
40 Command may be a series of Python scripts with arguments: [PYTHON_FILE [args] [PYTHON_FILE [args]...]]
41 Python file arguments, if any, must be comma-separated (without blank characters) and prefixed by "args:" (without quotes), e.g. myscript.py args:arg1,arg2=val,...
43 If PORT and MACHINE are not given, try to connect to the last active session on the local machine.
44 If PORT and MACHINE are given, try to connect to the remote session associated with PORT on MACHINE.
45 If MACHINE is not given, try to connect to the session associated to PORT on the local machine.
46 If PORT is not given, try to connect to the remote session associated to port 2810 on MACHINE.\n\n"""
47 parser = MyParser(usage=usage, epilog=epilog)
48 parser.add_option("-p", "--port", metavar="<port>", default=0,
49 action="store", type="string", dest="port",
50 help="The port to connect to."
52 parser.add_option("-m", "--machine", metavar="<machine>", default=0,
53 action="store", type="string", dest="host",
54 help="The machine to connect to."
57 (options, args) = parser.parse_args(args)
65 # :GLITCH: this code defines specific environment variables (OMNIORB_CONFIG, NSPORT,
66 # NSHOST) which are later used by other modules. Working, but not really "safe"...
69 # neither MACHINE nor PORT are given
70 # --- set omniORB configuration to current session if any
71 omniorbUserPath = os.environ['OMNIORB_USER_PATH']
72 fileOmniConfig = omniorbUserPath + '/.omniORB_' + os.environ['USER'] + '_last.cfg'
73 if os.path.isfile(fileOmniConfig):
74 os.environ['OMNIORB_CONFIG'] = fileOmniConfig
75 # --- set environment variables for port and hostname of NamingService
76 host, port = getNSparams()
82 # only MACHINE is given
84 _writeConfigFile(port, host)
89 host = socket.gethostname()
90 # both MACHINE and PORT are given
91 _writeConfigFile(port, host)
93 os.environ['NSPORT'] = port
94 os.environ['NSHOST'] = host
97 # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
98 def _writeConfigFile(port, host):
99 path = os.environ['OMNIORB_USER_PATH']
100 kwargs = {'with_username' : os.environ['USER']}
102 from ORBConfigFile import writeORBConfigFile
103 [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs)
105 os.environ['OMNIORB_CONFIG'] = filename