]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Add option to start SALOME on specific port (useful for testing)
authorvsr <vsr@opencascade.com>
Wed, 13 Mar 2013 13:18:27 +0000 (13:18 +0000)
committervsr <vsr@opencascade.com>
Wed, 13 Mar 2013 13:18:27 +0000 (13:18 +0000)
bin/launchConfigureParser.py
bin/runSalome.py
bin/searchFreePort.py

index 92b5e9aea20eb2a489e9a2341c2dc8018098f060..487e251034184547238c06375d8b6a99659e977d 100755 (executable)
@@ -74,6 +74,7 @@ plugins_nam    = "plugins"
 # values passed as arguments, NOT read from XML config file, but set from within this script
 appname_nam    = "appname"
 port_nam       = "port"
+useport_nam    = "useport"
 salomecfgname  = "salome"
 salomeappname  = "SalomeApp"
 script_nam     = "pyscript"
@@ -773,6 +774,17 @@ def CreateOptionParser (theAdditionalOptions=[]):
                             dest="server_launch_mode",
                             help=help_str)
 
+    # use port
+    help_str  = "Preferable port SALOME to be started on. "
+    help_str += "If specified port is not busy, SALOME session will start on it; "
+    help_str += "otherwise, any available port will be searched and used."
+    o_port = optparse.Option("--port",
+                             metavar="<port>",
+                             type="int",
+                             action="store",
+                             dest="use_port",
+                             help=help_str)
+
     # All options
     opt_list = [o_t,o_g, # GUI/Terminal
                 o_d,o_o, # Desktop
@@ -802,6 +814,7 @@ def CreateOptionParser (theAdditionalOptions=[]):
                 o_foreground,
                 o_wake_up,
                 o_slm,   # Server launch mode
+                o_port,  # Use port
                 ]
 
     #std_options = ["gui", "desktop", "log_file", "py_scripts", "resources",
@@ -1152,7 +1165,16 @@ def get_env(theAdditionalOptions=[], appname=salomeappname, cfgname=salomecfgnam
 
     # Server launch command
     if cmd_opts.server_launch_mode is not None:
-      args["server_launch_mode"] = cmd_opts.server_launch_mode
+        args["server_launch_mode"] = cmd_opts.server_launch_mode
+
+    # Server launch command
+    if cmd_opts.use_port is not None:
+        min_port = 2810
+        max_port = min_port + 100
+        if cmd_opts.use_port not in xrange(min_port, max_port+1):
+            print "Error: port number should be in range [%d, %d])" % (min_port, max_port)
+            sys.exit(1)
+        args[useport_nam] = cmd_opts.use_port
 
     # return arguments
     os.environ[config_var] = separator.join(dirs)
index f6e76652fe1427cb5edc5ddb99fd734465ea0bd2..dd60df33589e0870b055b8e30c2dd864e4e23c82 100755 (executable)
@@ -843,7 +843,7 @@ def main():
         pass
     if test:
         from searchFreePort import searchFreePort
-        searchFreePort(args, save_config)
+        searchFreePort(args, save_config, args.get('useport'))
         pass
     # --
     #setenv.main()
index 32d858f316ef623ebb80ada9f02943041505c925..392b8adcfa7b1e1d34fc5c29d0d53ceb764a891f 100644 (file)
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-def searchFreePort(args={}, save_config=1):
+def searchFreePort(args={}, save_config=1, use_port=None):
   """
   Search free port for SALOME session.
   Returns first found free port number.
   """
   import sys, os, re, shutil
-  print "Searching for a free port for naming service:",
 
   # :NOTE: Under windows:
   #        netstat options -l and -t are unavailable
@@ -53,13 +52,8 @@ def searchFreePort(args={}, save_config=1):
       pass
     return False
   #
-  NSPORT=2810
-  limit=NSPORT+100
-  #
 
-  while 1:
-    if not portIsUsed(NSPORT, ports):
-      print "%s - OK"%(NSPORT)
+  def setup_config(nsport):
       #
       from salome_utils import generateFileName, getHostName
       hostname = getHostName()
@@ -68,12 +62,11 @@ def searchFreePort(args={}, save_config=1):
       appli = os.getenv("APPLI")
       kwargs={}
       if appli is not None:
-        home = os.path.join(os.path.realpath(home), appli,"USERS")
+        home = os.path.join(os.path.realpath(home), appli, "USERS")
         kwargs["with_username"]=True
       #
       from ORBConfigFile import writeORBConfigFile
-      omniorb_config, giopsize = writeORBConfigFile(home, hostname, NSPORT, kwargs)
-
+      omniorb_config, giopsize = writeORBConfigFile(home, hostname, nsport, kwargs)
       args['port'] = os.environ['NSPORT']
       #
       if save_config:
@@ -99,6 +92,29 @@ def searchFreePort(args={}, save_config=1):
         except:
           pass
       #
+
+  if use_port:
+    print "Check if port can be used: %d" % use_port,
+    if not portIsUsed(use_port, ports):
+      print "- OK"
+      setup_config(use_port)
+      return
+    else:
+      print "- KO: port is busy"
+    pass
+  #
+  
+  print "Searching for a free port for naming service:",
+  #
+
+  NSPORT=2810
+  limit=NSPORT+100
+  #
+
+  while 1:
+    if not portIsUsed(NSPORT, ports):
+      print "%s - OK"%(NSPORT)
+      setup_config(NSPORT)
       break
     print "%s"%(NSPORT),
     if NSPORT == limit:
@@ -108,4 +124,6 @@ def searchFreePort(args={}, save_config=1):
       raise RuntimeError, msg
     NSPORT=NSPORT+1
     pass
+  #
+  
   return