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
29 def startSession(modules=[]):
33 _session = SalomeSession(modules)
36 def getShortHostName():
38 gives Hostname without domain extension.
39 SALOME naming service needs short Hostnames (without domain extension).
40 HOSTNAME is not allways defined in environment,
41 socket.gethostname() gives short or complete Hostname, depending on
44 from salome_utils import getShortHostName
45 return getShortHostName()
49 Search free port for SALOME session.
50 Returns first found free port number.
52 print "Searching a free port for naming service:",
53 from salome_utils import generateFileName, getHostName
54 hostname = getHostName()
59 status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
61 home = os.getenv("HOME")
62 appli = os.getenv("APPLI")
65 home = os.path.join(home, appli,"USERS")
66 kwargs["with_username"]=True
67 omniorb_config = generateFileName(home, prefix="omniORB",
73 f = open(omniorb_config, "w")
74 f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
76 os.environ['OMNIORB_CONFIG'] = omniorb_config
77 last_running_config = generateFileName(home, prefix="omniORB",
82 os.environ['LAST_RUNNING_CONFIG'] = last_running_config
83 if os.access(last_running_config,os.F_OK):
84 os.unlink(last_running_config)
86 os.symlink(omniorb_config,last_running_config)
91 msg += "Can not find a free port to launch omniNames\n"
92 msg += "Kill the running servers and try again.\n"
96 os.environ['NSHOST'] = hostname
97 os.environ['NSPORT'] = str(NSPORT)
101 class SalomeSession(object):
103 import killSalomeWithPort
105 def __init__(self, modules):
107 sys.argv = ["dummy.py"]
108 sys.argv += ["--terminal"]
110 sys.argv += ['--modules=%s'%(",".join(modules))]
112 runSalome.clt, runSalome.args = runSalome.main()
118 runSalome.killLocalPort()