1 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 def startSession(modules=[]):
31 _session = SalomeSession(modules)
34 def getShortHostName():
36 gives Hostname without domain extension.
37 SALOME naming service needs short Hostnames (without domain extension).
38 HOSTNAME is not allways defined in environment,
39 socket.gethostname() gives short or complete Hostname, depending on
42 from salome_utilities import getShortHostName
43 return getShortHostName()
47 Search free port for SALOME session.
48 Returns first found free port number.
50 print "Searching a free port for naming service:",
51 from salome_utilities import generateFileName, getHostName
52 hostname = getHostName()
57 status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
59 home = os.getenv("HOME")
60 appli = os.getenv("APPLI")
61 if appli is not None: home = os.path.join(home, appli)
62 omniorb_config = generateFileName(home, prefix="omniORB",
67 f = open(omniorb_config, "w")
68 f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
70 os.environ['OMNIORB_CONFIG'] = omniorb_config
71 last_running_config = generateFileName(home, prefix="omniORB",
75 os.environ['LAST_RUNNING_CONFIG'] = last_running_config
76 if os.access(last_running_config,os.F_OK):
77 os.unlink(last_running_config)
79 os.symlink(omniorb_config,last_running_config)
84 msg += "Can not find a free port to launch omniNames\n"
85 msg += "Kill the running servers and try again.\n"
89 os.environ['NSHOST'] = hostname
90 os.environ['NSPORT'] = str(NSPORT)
94 class SalomeSession(object):
96 import killSalomeWithPort
98 def __init__(self, modules):
100 sys.argv = ["dummy.py"]
101 sys.argv += ["--terminal"]
103 sys.argv += ['--modules=%s'%(",".join(modules))]
105 runSalome.clt, runSalome.args = runSalome.main()
111 runSalome.killLocalPort()