# 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"
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
o_foreground,
o_wake_up,
o_slm, # Server launch mode
+ o_port, # Use port
]
#std_options = ["gui", "desktop", "log_file", "py_scripts", "resources",
# 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)
# 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
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()
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:
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:
raise RuntimeError, msg
NSPORT=NSPORT+1
pass
+ #
+
return