1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 ## @package salome_session
23 # \brief Module that provides the SalomeSession object that helps to launch
24 # a SALOME script session
35 def startSession(modules=[]):
39 _session = SalomeSession(modules)
42 def getShortHostName():
44 gives Hostname without domain extension.
45 SALOME naming service needs short Hostnames (without domain extension).
46 HOSTNAME is not allways defined in environment,
47 socket.gethostname() gives short or complete Hostname, depending on
50 from salome_utils import getShortHostName
51 return getShortHostName()
55 Search free port for SALOME session.
56 Returns first found free port number.
58 print "Searching a free port for naming service:",
59 from salome_utils import generateFileName, getHostName
60 hostname = getHostName()
65 status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
67 home = os.getenv("HOME")
68 appli = os.getenv("APPLI")
71 home = os.path.join(home, appli,"USERS")
72 kwargs["with_username"]=True
73 omniorb_config = generateFileName(home, prefix="omniORB",
79 f = open(omniorb_config, "w")
80 f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
82 os.environ['OMNIORB_CONFIG'] = omniorb_config
83 last_running_config = generateFileName(home, prefix="omniORB",
88 os.environ['LAST_RUNNING_CONFIG'] = last_running_config
89 if os.access(last_running_config,os.F_OK):
90 os.unlink(last_running_config)
92 os.symlink(omniorb_config,last_running_config)
97 msg += "Can not find a free port to launch omniNames\n"
98 msg += "Kill the running servers and try again.\n"
102 os.environ['NSHOST'] = hostname
103 os.environ['NSPORT'] = str(NSPORT)
107 class SalomeSession(object):
108 """Salome session launcher"""
110 import killSalomeWithPort
112 def __init__(self, modules):
114 sys.argv = ["dummy.py"]
115 sys.argv += ["--terminal"]
117 sys.argv += ['--modules=%s'%(",".join(modules))]
119 runSalome.clt, runSalome.args = runSalome.main()
125 runSalome.killLocalPort()