+ value_conv = booleans[value.strip().lower()]
+ for attribute in args:
+ setattr(parser.values, attribute, value_conv)
+ except KeyError:
+ raise optparse.OptionValueError(
+ "option %s: invalid boolean value: %s (choose from %s)"
+ % (opt, value, boolean_choices))
+ else:
+ for attribute in args:
+ setattr(parser.values, attribute, value)
+
+def CreateOptionParser (theAdditionalOptions=None):
+ if theAdditionalOptions is None:
+ theAdditionalOptions = []
+ # GUI/Terminal. Default: GUI
+ help_str = "Launch without GUI (in the terminal mode)."
+ o_t = optparse.Option("-t",
+ "--terminal",
+ action="store_false",
+ dest="gui",
+ help=help_str)
+
+ help_str = "Launch in Batch Mode. (Without GUI on batch machine)"
+ o_b = optparse.Option("-b",
+ "--batch",
+ action="store_true",
+ dest="batch",
+ help=help_str)
+
+ help_str = "Launch in GUI mode [default]."
+ o_g = optparse.Option("-g",
+ "--gui",
+ action="store_true",
+ dest="gui",
+ help=help_str)
+
+ # Show Desktop (inly in GUI mode). Default: True
+ help_str = "1 to activate GUI desktop [default], "
+ help_str += "0 to not activate GUI desktop (Session_Server starts, but GUI is not shown). "
+ help_str += "Ignored in the terminal mode."
+ o_d = optparse.Option("-d",
+ "--show-desktop",
+ metavar="<1/0>",
+ #type="choice", choices=boolean_choices,
+ type="string",
+ action="callback", callback=store_boolean, callback_args=('desktop',),
+ dest="desktop",
+ help=help_str)
+ help_str = "Do not activate GUI desktop (Session_Server starts, but GUI is not shown). "
+ help_str += "The same as --show-desktop=0."
+ o_o = optparse.Option("-o",
+ "--hide-desktop",
+ action="store_false",
+ dest="desktop",
+ help=help_str)
+
+ # Use logger or log-file. Default: nothing.
+ help_str = "Redirect messages to the CORBA collector."
+ #o4 = optparse.Option("-l", "--logger", action="store_true", dest="logger", help=help_str)
+ o_l = optparse.Option("-l",
+ "--logger",
+ action="store_const", const="CORBA",
+ dest="log_file",
+ help=help_str)
+ help_str = "Redirect messages to the <log-file>"
+ o_f = optparse.Option("-f",
+ "--log-file",
+ metavar="<log-file>",
+ type="string",
+ action="store",
+ dest="log_file",
+ help=help_str)
+
+ # Configuration XML file. Default: see defaultUserFile() function
+ help_str = "Parse application settings from the <file> "
+ help_str += "instead of default %s" % defaultUserFile()
+ o_r = optparse.Option("-r",
+ "--resources",
+ metavar="<file>",
+ type="string",
+ action="store",
+ dest="resources",
+ help=help_str)
+
+ # Use own xterm for each server. Default: False.
+ help_str = "Launch each SALOME server in own xterm console"
+ o_x = optparse.Option("-x",
+ "--xterm",
+ action="store_true",
+ dest="xterm",
+ help=help_str)
+
+ # Modules. Default: Like in configuration files.
+ help_str = "SALOME modules list (where <module1>, <module2> are the names "
+ help_str += "of SALOME modules which should be available in the SALOME session)"
+ o_m = optparse.Option("-m",
+ "--modules",
+ metavar="<module1,module2,...>",
+ type="string",
+ action="append",
+ dest="modules",
+ help=help_str)
+
+ # Embedded servers. Default: Like in configuration files.
+ help_str = "CORBA servers to be launched in the Session embedded mode. "
+ help_str += "Valid values for <serverN>: %s " % ", ".join( embedded_choices )
+ help_str += "[by default the value from the configuration files is used]"
+ o_e = optparse.Option("-e",
+ "--embedded",
+ metavar="<server1,server2,...>",
+ type="string",
+ action="callback",
+ dest="embedded",
+ callback=check_embedded,
+ help=help_str)
+
+ # Standalone servers. Default: Like in configuration files.
+ help_str = "CORBA servers to be launched in the standalone mode (as separate processes). "
+ help_str += "Valid values for <serverN>: %s " % ", ".join( standalone_choices )
+ help_str += "[by default the value from the configuration files is used]"
+ o_s = optparse.Option("-s",
+ "--standalone",
+ metavar="<server1,server2,...>",
+ type="string",
+ action="callback",
+ dest="standalone",
+ callback=check_standalone,
+ help=help_str)
+
+ # Kill with port. Default: False.
+ help_str = "Kill SALOME with the current port"
+ o_p = optparse.Option("-p",
+ "--portkill",
+ action="store_true",
+ dest="portkill",
+ help=help_str)
+
+ # Kill all. Default: False.
+ help_str = "Kill all running SALOME sessions"
+ o_k = optparse.Option("-k",
+ "--killall",
+ action="store_true",
+ dest="killall",
+ help=help_str)
+
+ # Additional python interpreters. Default: 0.
+ help_str = "The number of additional external python interpreters to run. "
+ help_str += "Each additional python interpreter is run in separate "
+ help_str += "xterm session with properly set SALOME environment"
+ o_i = optparse.Option("-i",
+ "--interp",
+ metavar="<N>",
+ type="int",
+ action="store",
+ dest="interp",
+ help=help_str)
+
+ # Splash. Default: True.
+ help_str = "1 to display splash screen [default], "
+ help_str += "0 to disable splash screen. "
+ help_str += "This option is ignored in the terminal mode. "
+ help_str += "It is also ignored if --show-desktop=0 option is used."
+ o_z = optparse.Option("-z",
+ "--splash",
+ metavar="<1/0>",
+ #type="choice", choices=boolean_choices,
+ type="string",
+ action="callback", callback=store_boolean, callback_args=('splash',),
+ dest="splash",
+ help=help_str)
+
+ # Catch exceptions. Default: True.
+ help_str = "1 (yes,true,on,ok) to enable centralized exception handling [default], "
+ help_str += "0 (no,false,off,cancel) to disable centralized exception handling."
+ o_c = optparse.Option("-c",
+ "--catch-exceptions",
+ metavar="<1/0>",
+ #type="choice", choices=boolean_choices,
+ type="string",
+ action="callback", callback=store_boolean, callback_args=('catch_exceptions',),
+ dest="catch_exceptions",
+ help=help_str)
+
+ # Print free port and exit
+ help_str = "Print free port and exit"
+ o_a = optparse.Option("--print-port",
+ action="store_true",
+ dest="print_port", default=False,
+ help=help_str)
+
+ # Do not relink ${HOME}/.omniORB_last.cfg
+ help_str = "Do not save current configuration ${HOME}/.omniORB_last.cfg"
+ o_n = optparse.Option("--nosave-config",
+ action="store_false",
+ dest="save_config", default=True,
+ help=help_str)
+
+ # Launch with interactive python console. Default: False.
+ help_str = "Launch with interactive python console."
+ o_pi = optparse.Option("--pinter",
+ action="store_true",
+ dest="pinter",
+ help=help_str)
+
+ # Print Naming service port into a user file. Default: False.
+ help_str = "Print Naming Service Port into a user file."
+ o_nspl = optparse.Option("--ns-port-log",
+ metavar="<ns_port_log_file>",
+ type="string",
+ action="store",
+ dest="ns_port_log_file",
+ help=help_str)
+
+ # Write/read test script file with help of TestRecorder. Default: False.
+ help_str = "Write/read test script file with help of TestRecorder."
+ o_test = optparse.Option("--test",
+ metavar="<test_script_file>",
+ type="string",
+ action="store",
+ dest="test_script_file",
+ help=help_str)
+
+ # Reproducing test script with help of TestRecorder. Default: False.
+ help_str = "Reproducing test script with help of TestRecorder."
+ o_play = optparse.Option("--play",
+ metavar="<play_script_file>",
+ type="string",
+ action="store",
+ dest="play_script_file",
+ help=help_str)
+
+ # gdb session
+ help_str = "Launch session with gdb"
+ o_gdb = optparse.Option("--gdb-session",
+ action="store_true",
+ dest="gdb_session", default=False,
+ help=help_str)
+
+ # ddd session
+ help_str = "Launch session with ddd"
+ o_ddd = optparse.Option("--ddd-session",
+ action="store_true",
+ dest="ddd_session", default=False,
+ help=help_str)
+
+
+ # valgrind session
+ help_str = "Launch session with valgrind $VALGRIND_OPTIONS"
+ o_valgrind = optparse.Option("--valgrind-session",
+ action="store_true",
+ dest="valgrind_session", default=False,
+ help=help_str)
+
+ # shutdown-servers. Default: False.
+ help_str = "1 to shutdown standalone servers when leaving python interpreter, "
+ help_str += "0 to keep the standalone servers as daemon [default]. "
+ help_str += "This option is only useful in batchmode "
+ help_str += "(terminal mode or without showing desktop)."
+ o_shutdown = optparse.Option("-w",
+ "--shutdown-servers",
+ metavar="<1/0>",
+ #type="choice", choices=boolean_choices,
+ type="string",
+ action="callback", callback=store_boolean, callback_args=('shutdown_servers',),
+ dest="shutdown_servers",
+ help=help_str)
+
+ # foreground. Default: True.
+ help_str = "0 and runSalome exits after have launched the gui, "
+ help_str += "1 to launch runSalome in foreground mode [default]."
+ o_foreground = optparse.Option("--foreground",
+ metavar="<1/0>",
+ #type="choice", choices=boolean_choices,
+ type="string",
+ action="callback", callback=store_boolean, callback_args=('foreground',),
+ dest="foreground",
+ help=help_str)
+
+ # wake up session
+ help_str = "Wake up a previously closed session. "
+ help_str += "The session object is found in the naming service pointed by the variable OMNIORB_CONFIG. "
+ help_str += "If this variable is not setted, the last configuration is taken. "
+ o_wake_up = optparse.Option("--wake-up-session",
+ action="store_true",
+ dest="wake_up_session", default=False,
+ help=help_str)
+
+ # server launch mode
+ help_str = "Mode used to launch server processes (daemon or fork)."
+ o_slm = optparse.Option("--server-launch-mode",
+ metavar="<server_launch_mode>",
+ type="choice",
+ choices=["daemon","fork"],
+ action="store",
+ 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)
+
+ # SIMAN launch mode
+ help_str = "Special mode for interacting with SIMAN."
+ o_siman = optparse.Option("--siman",
+ action="store_true",
+ dest="siman",
+ help=help_str)
+
+ # SIMAN study
+ help_str = "SIMAN study identifier."
+ o_siman_study = optparse.Option("--siman-study",
+ metavar="<id>",
+ type="string",
+ action="store",
+ dest="siman_study",
+ help=help_str)
+
+ # SIMAN scenario
+ help_str = "SIMAN scenario identifier."
+ o_siman_scenario = optparse.Option("--siman-scenario",
+ metavar="<id>",
+ type="string",
+ action="store",
+ dest="siman_scenario",
+ help=help_str)
+
+ # SIMAN user
+ help_str = "SIMAN user identifier."
+ o_siman_user = optparse.Option("--siman-user",
+ metavar="<id>",
+ type="string",
+ action="store",
+ dest="siman_user",
+ help=help_str)
+
+ # All options
+ opt_list = [o_t,o_g, # GUI/Terminal
+ o_d,o_o, # Desktop
+ o_b, # Batch
+ o_l,o_f, # Use logger or log-file
+ o_r, # Configuration XML file
+ o_x, # xterm
+ o_m, # Modules
+ o_e, # Embedded servers
+ o_s, # Standalone servers
+ o_p, # Kill with port
+ o_k, # Kill all
+ o_i, # Additional python interpreters
+ o_z, # Splash
+ o_c, # Catch exceptions
+ o_a, # Print free port and exit
+ o_n, # --nosave-config
+ o_pi, # Interactive python console
+ o_nspl,
+ o_test, # Write/read test script file with help of TestRecorder
+ o_play, # Reproducing test script with help of TestRecorder
+ o_gdb,
+ o_ddd,
+ o_valgrind,
+ o_shutdown,
+ o_foreground,
+ o_wake_up,
+ o_slm, # Server launch mode
+ o_port, # Use port
+ o_siman, # Siman launch mode
+ o_siman_study, # Siman study
+ o_siman_scenario,# Siman scenario
+ o_siman_user, # Siman user
+ ]
+
+ #std_options = ["gui", "desktop", "log_file", "resources",
+ # "xterm", "modules", "embedded", "standalone",
+ # "portkill", "killall", "interp", "splash",
+ # "catch_exceptions", "print_port", "save_config", "ns_port_log_file"]
+
+ opt_list += theAdditionalOptions
+
+ a_usage = """%prog [options] [STUDY_FILE] [PYTHON_FILE [args] [PYTHON_FILE [args]...]]
+Python file arguments, if any, must be comma-separated (without blank characters) and prefixed by "args:" (without quotes), e.g. myscript.py args:arg1,arg2=val,...
+"""
+ version_str = "Salome %s" % version()
+ pars = optparse.OptionParser(usage=a_usage, version=version_str, option_list=opt_list)
+
+ return pars
+
+# -----------------------------------------------------------------------------
+
+###
+# Get the environment
+###
+
+# this attribute is obsolete
+args = {}
+#def get_env():
+#args = []
+def get_env(theAdditionalOptions=None, appname=salomeappname, cfgname=salomecfgname):
+ ###
+ # Collect launch configuration files:
+ # - The environment variable "<appname>Config" (SalomeAppConfig) which can
+ # define a list of directories (separated by ':' or ';' symbol) is checked
+ # - If the environment variable "<appname>Config" is not set, only
+ # ${GUI_ROOT_DIR}/share/salome/resources/gui is inspected
+ # - ${GUI_ROOT_DIR}/share/salome/resources/gui directory is always inspected
+ # so it is not necessary to put it in the "<appname>Config" variable
+ # - The directories which are inspected are checked for files "<appname?salomeappname>.xml"
+ # (SalomeApp.xml) which define SALOME configuration
+ # - These directories are analyzed beginning from the last one in the list,
+ # so the first directory listed in "<appname>Config" environment variable
+ # has higher priority: it means that if some configuration options
+ # is found in the next analyzed cofiguration file - it will be replaced
+ # - The last configuration file which is parsed is user configuration file
+ # situated in the home directory (if it exists):
+ # * ~/.config/salome/.<appname>rc[.<version>]" for Linux (e.g. ~/.config/salome/.SalomeApprc.6.4.0)
+ # * ~/<appname>.xml[.<version>] for Windows (e.g. ~/SalomeApp.xml.6.4.0)
+ # - Command line options have the highest priority and replace options
+ # specified in configuration file(s)
+ ###
+
+ if theAdditionalOptions is None:
+ theAdditionalOptions = []
+
+ global args
+ config_var = appname+'Config'
+
+ # check KERNEL_ROOT_DIR
+ kernel_root_dir = os.environ.get("KERNEL_ROOT_DIR", None)
+ if kernel_root_dir is None:
+ print """
+ For each SALOME module, the environment variable <moduleN>_ROOT_DIR must be set.
+ KERNEL_ROOT_DIR is mandatory.
+ """
+ sys.exit(1)
+
+ ############################
+ # parse command line options
+ pars = CreateOptionParser(theAdditionalOptions)
+ (cmd_opts, cmd_args) = pars.parse_args(sys.argv[1:])
+ ############################
+
+ # Process --print-port option
+ if cmd_opts.print_port:
+ from searchFreePort import searchFreePort
+ searchFreePort({})
+ print "port:%s"%(os.environ['NSPORT'])
+
+ try:
+ import PortManager
+ PortManager.releasePort(os.environ['NSPORT'])
+ except ImportError:
+ pass
+
+ sys.exit(0)