From: vsr Date: Wed, 13 Mar 2013 13:18:27 +0000 (+0000) Subject: Add option to start SALOME on specific port (useful for testing) X-Git-Tag: V6_main_FINAL~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ceef9ca6627504172c98f75386dbc052f6710768;p=modules%2Fkernel.git Add option to start SALOME on specific port (useful for testing) --- diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 92b5e9aea..487e25103 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -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="", + 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) diff --git a/bin/runSalome.py b/bin/runSalome.py index f6e76652f..dd60df335 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -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() diff --git a/bin/searchFreePort.py b/bin/searchFreePort.py index 32d858f31..392b8adcf 100644 --- a/bin/searchFreePort.py +++ b/bin/searchFreePort.py @@ -22,13 +22,12 @@ # 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