1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2010 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
24 ## @package salome_session
25 # \brief Module that provides the SalomeSession object that helps to launch
26 # a SALOME script session
36 def startSession(modules=[]):
40 _session = SalomeSession(modules)
43 def getShortHostName():
45 gives Hostname without domain extension.
46 SALOME naming service needs short Hostnames (without domain extension).
47 HOSTNAME is not allways defined in environment,
48 socket.gethostname() gives short or complete Hostname, depending on
51 from salome_utils import getShortHostName
52 return getShortHostName()
56 Search free port for SALOME session.
57 Returns first found free port number.
59 print "Searching a free port for naming service:",
60 from salome_utils import generateFileName, getHostName
61 hostname = getHostName()
66 status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
68 home = os.getenv("HOME")
69 appli = os.getenv("APPLI")
72 home = os.path.join(home, appli,"USERS")
73 kwargs["with_username"]=True
74 omniorb_config = generateFileName(home, prefix="omniORB",
80 f = open(omniorb_config, "w")
81 f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
83 os.environ['OMNIORB_CONFIG'] = omniorb_config
84 last_running_config = generateFileName(home, prefix="omniORB",
89 os.environ['LAST_RUNNING_CONFIG'] = last_running_config
90 if os.access(last_running_config,os.F_OK):
91 os.unlink(last_running_config)
93 os.symlink(omniorb_config,last_running_config)
98 msg += "Can not find a free port to launch omniNames\n"
99 msg += "Kill the running servers and try again.\n"
100 raise RuntimeError, msg
103 os.environ['NSHOST'] = hostname
104 os.environ['NSPORT'] = str(NSPORT)
108 class SalomeSession(object):
109 """Salome session launcher"""
111 import killSalomeWithPort
113 def __init__(self, modules):
115 sys.argv = ["dummy.py"]
116 sys.argv += ["--terminal"]
118 sys.argv += ['--modules=%s'%(",".join(modules))]
120 runSalome.clt, runSalome.args = runSalome.main()
126 runSalome.killLocalPort()