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 return string.split(socket.gethostname(),'.')[0]
45 print "Searching a free port for naming service:",
51 status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
53 home = os.environ['HOME']
54 appli=os.environ.get("APPLI")
56 #Run outside application context
59 home='%s/%s'%(home,appli)
60 hostname=getShortHostName()
61 omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, NSPORT)
62 os.environ['OMNIORB_CONFIG'] = omniorb_config
63 f = open(omniorb_config, "w")
64 f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
66 last_running_config = '%s/.omniORB_%s_last.cfg'%(home, hostname)
67 os.environ['LAST_RUNNING_CONFIG'] = last_running_config
68 if os.access(last_running_config,os.F_OK):
69 os.unlink(last_running_config)
71 os.symlink(omniorb_config,last_running_config)
72 # LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg
77 msg += "I Can't find a free port to launch omniNames\n"
78 msg += "I suggest you to kill the running servers and try again.\n"
82 os.environ['NSHOST']=hostname
83 os.environ['NSPORT']=str(NSPORT)
87 class SalomeSession(object):
89 import killSalomeWithPort
91 def __init__(self, modules):
93 sys.argv = ["dummy.py"]
94 sys.argv += ["--terminal"]
96 sys.argv += ['--modules=%s'%(",".join(modules))]
98 runSalome.clt, runSalome.args = runSalome.main()
104 runSalome.killLocalPort()