2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 ## @package salome_session
25 # \brief Module that provides the SalomeSession object that helps to launch
26 # a SALOME script session
37 def startSession(modules=[]):
41 _session = SalomeSession(modules)
44 def getShortHostName():
46 gives Hostname without domain extension.
47 SALOME naming service needs short Hostnames (without domain extension).
48 HOSTNAME is not allways defined in environment,
49 socket.gethostname() gives short or complete Hostname, depending on
52 from salome_utils import getShortHostName
53 return getShortHostName()
57 Search free port for SALOME session.
58 Returns first found free port number.
60 print "Searching a free port for naming service:",
61 from salome_utils import generateFileName, getHostName
62 hostname = getHostName()
67 status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
69 home = os.getenv("HOME")
70 appli = os.getenv("APPLI")
73 home = os.path.join(home, appli,"USERS")
74 kwargs["with_username"]=True
75 omniorb_config = generateFileName(home, prefix="omniORB",
81 f = open(omniorb_config, "w")
82 f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
84 os.environ['OMNIORB_CONFIG'] = omniorb_config
85 last_running_config = generateFileName(home, prefix="omniORB",
90 os.environ['LAST_RUNNING_CONFIG'] = last_running_config
91 if os.access(last_running_config,os.F_OK):
92 os.unlink(last_running_config)
94 os.symlink(omniorb_config,last_running_config)
99 msg += "Can not find a free port to launch omniNames\n"
100 msg += "Kill the running servers and try again.\n"
101 raise RuntimeError, msg
104 os.environ['NSHOST'] = hostname
105 os.environ['NSPORT'] = str(NSPORT)
109 class SalomeSession(object):
110 """Salome session launcher"""
112 import killSalomeWithPort
114 def __init__(self, modules):
116 sys.argv = ["dummy.py"]
117 sys.argv += ["--terminal"]
119 sys.argv += ['--modules=%s'%(",".join(modules))]
121 runSalome.clt, runSalome.args = runSalome.main()
127 runSalome.killLocalPort()