Salome HOME
enable running without "APPLI" env var
[modules/kernel.git] / bin / salome_session.py
index d2ca5b09439b6cdbfc4b3f999fc0940fa31d8bee..d3d6c4fe383f19bf4bcbb79401b6dd90b585a27f 100644 (file)
@@ -1,5 +1,5 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -36,6 +36,7 @@ _session = None
 def startSession(modules=[]):
     global _session
     if _session: return
+    from searchFreePort import searchFreePort
     searchFreePort()
     _session = SalomeSession(modules)
     return
@@ -51,59 +52,6 @@ def getShortHostName():
     from salome_utils import getShortHostName
     return getShortHostName()
 
-def searchFreePort():
-    """
-    Search free port for SALOME session.
-    Returns first found free port number.
-    """
-    print "Searching a free port for naming service:",
-    from salome_utils import generateFileName, getHostName
-    hostname = getHostName()
-    NSPORT = 2810
-    limit  = NSPORT+100
-    while 1:
-        print "%s "%(NSPORT),
-        status = os.system("netstat -ltn | grep -E :%s"%(NSPORT))
-        if status:
-            home  = os.getenv("HOME")
-            appli = os.getenv("APPLI")
-            kwargs={}
-            if appli is not None: 
-              home = os.path.join(os.path.realpath(home), appli,"USERS")
-              kwargs["with_username"]=True
-            omniorb_config = generateFileName(home, prefix="omniORB",
-                                              extension="cfg",
-                                              hidden=True,
-                                              with_hostname=True,
-                                              with_port=NSPORT,
-                                              **kwargs)
-            f = open(omniorb_config, "w")
-            f.write("ORBInitRef NameService=corbaname::%s:%s\n"%(hostname, NSPORT))
-            f.close()
-            os.environ['OMNIORB_CONFIG'] = omniorb_config
-            last_running_config = generateFileName(home, prefix="omniORB",
-                                                   suffix="last",
-                                                   extension="cfg",
-                                                   hidden=True,
-                                                   **kwargs)
-            os.environ['LAST_RUNNING_CONFIG'] = last_running_config
-            if os.access(last_running_config,os.F_OK):
-                os.unlink(last_running_config)
-                pass
-            os.symlink(omniorb_config,last_running_config)
-            print "- Ok"
-            break
-        if NSPORT == limit:
-            msg  = ""
-            msg += "Can not find a free port to launch omniNames\n"
-            msg += "Kill the running servers and try again.\n"
-            raise RuntimeError, msg
-        NSPORT = NSPORT+1
-        pass
-    os.environ['NSHOST'] = hostname
-    os.environ['NSPORT'] = str(NSPORT)
-    return NSPORT
-
 
 class SalomeSession(object):
     """Salome session launcher"""