Salome HOME
- Major update for launcher:
[modules/kernel.git] / bin / launchConfigureParser.py
index 399c40ef73a7bcd0595db57cfb4012a0fbdb9f25..7fde55b7987e62405bc5e53ba2e90fc8a0c68432 100755 (executable)
@@ -1,20 +1,24 @@
-# Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
-#           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+#  -*- coding: iso-8859-1 -*-
+#  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 #
-# This library is distributed in the hope that it will be useful
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
+#  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
 #
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
 import os, glob, string, sys, re
@@ -51,6 +55,11 @@ except_nam     = "noexcepthandler"
 terminal_nam   = "terminal"
 pinter_nam     = "pinter"
 batch_nam      = "batch"
+test_nam       = "test"
+play_nam       = "play"
+gdb_session_nam = "gdb_session"
+ddd_session_nam = "ddd_session"
+shutdown_servers_nam = "shutdown_servers"
 
 # values in XML configuration file giving specific module parameters (<module_name> section)
 # which are stored in opts with key <module_name>_<parameter> (eg SMESH_plugins)
@@ -64,11 +73,11 @@ script_nam     = "pyscript"
 
 # possible choices for the "embedded" and "standalone" parameters
 embedded_choices   = [ "registry", "study", "moduleCatalog", "cppContainer", "SalomeAppEngine" ]
-standalone_choices = [ "registry", "study", "moduleCatalog", "cppContainer", "pyContainer", "supervContainer"]
+standalone_choices = [ "registry", "study", "moduleCatalog", "cppContainer", "pyContainer"]
 
 # values of boolean type (must be '0' or '1').
 # xml_parser.boolValue() is used for correct setting
-boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam, pinter_nam )
+boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam, pinter_nam, shutdown_servers_nam )
 intKeys = ( interp_nam, )
 
 # values of list type
@@ -446,7 +455,9 @@ def CreateOptionParser (theAdditionalOptions=[]):
     help_str  = "Python script(s) to be imported. Python scripts are imported "
     help_str += "in the order of their appearance. In GUI mode python scripts "
     help_str += "are imported in the embedded python interpreter of current study, "
-    help_str += "otherwise in an external python interpreter"
+    help_str += "otherwise in an external python interpreter. "
+    help_str += "Note: this option is obsolete. Instead you can pass Python script(s) "
+    help_str += "directly as positional parameter."
     o_u = optparse.Option("-u",
                           "--execute",
                           metavar="<script1,script2,...>",
@@ -595,6 +606,51 @@ def CreateOptionParser (theAdditionalOptions=[]):
                              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)
+    
+    # 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("--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)
+    
     # All options
     opt_list = [o_t,o_g, # GUI/Terminal
                 o_d,o_o, # Desktop
@@ -614,8 +670,13 @@ def CreateOptionParser (theAdditionalOptions=[]):
                 o_a,     # Print free port and exit
                 o_n,     # --nosave-config
                 o_pi,    # Interactive python console
-                o_nspl]
-                
+                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_shutdown,
+                ]
 
     #std_options = ["gui", "desktop", "log_file", "py_scripts", "resources",
     #               "xterm", "modules", "embedded", "standalone",
@@ -624,7 +685,7 @@ def CreateOptionParser (theAdditionalOptions=[]):
 
     opt_list += theAdditionalOptions
 
-    a_usage = "%prog [options] [STUDY_FILE]"
+    a_usage = "%prog [options] [STUDY_FILE] [PYTHON_FILE [PYTHON_FILE ...]]"
     version_str = "Salome %s" % version()
     pars = optparse.OptionParser(usage=a_usage, version=version_str, option_list=opt_list)
 
@@ -701,9 +762,16 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
             dirs += re.split(';', os.getenv(config_var))
         else:
             dirs += re.split('[;|:]', os.getenv(config_var))
-            
+
+    gui_available = True
     if os.getenv("GUI_ROOT_DIR") and os.path.isdir( os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui" ):
         dirs += [os.getenv("GUI_ROOT_DIR") + "/share/salome/resources/gui"]
+       pass
+    else:
+       gui_available = False
+       if os.getenv("KERNEL_ROOT_DIR") and os.path.isdir( os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/appliskel" ):
+           dirs += [os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/appliskel"]
+       pass
     os.environ[config_var] = separator.join(dirs)
 
     dirs.reverse() # reverse order, like in "path" variable - FILO-style processing
@@ -800,6 +868,10 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
         args[gui_nam] = cmd_opts.gui
     if cmd_opts.batch is not None:
         args[batch_nam] = True
+
+    if not gui_available:
+       args[gui_nam] = False
+       
     if args[gui_nam]:
         args["session_gui"] = True
         if cmd_opts.desktop is not None:
@@ -808,8 +880,6 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
         if args["session_gui"]:
             if cmd_opts.splash is not None:
                 args[splash_nam] = cmd_opts.splash
-        if len(cmd_args) > 0:
-            args["study_hdf"] = cmd_args[0]
     else:
         args["session_gui"] = False
         args[splash_nam] = False
@@ -831,6 +901,13 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
         listlist = cmd_opts.py_scripts
         for listi in listlist:
             args[script_nam] += re.split( "[:;,]", listi)
+    for arg in cmd_args:
+        if arg[-3:] == ".py":
+            args[script_nam].append(arg)
+        elif not args["study_hdf"]:
+            args["study_hdf"] = arg
+            pass
+        pass
 
     # xterm
     if cmd_opts.xterm is not None: args[xterm_nam] = cmd_opts.xterm
@@ -883,7 +960,22 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
     # Interactive python console
     if cmd_opts.pinter is not None:
         args[pinter_nam] = cmd_opts.pinter
-
+       
+    # Gdb session in xterm
+    if cmd_opts.gdb_session is not None:
+        args[gdb_session_nam] = cmd_opts.gdb_session
+
+    # Ddd session in xterm
+    if cmd_opts.ddd_session is not None:
+        args[ddd_session_nam] = cmd_opts.ddd_session
+
+    # Shutdown servers
+    if cmd_opts.shutdown_servers is None:
+        args[shutdown_servers_nam] = 0
+    else:
+        args[shutdown_servers_nam] = cmd_opts.shutdown_servers
+        pass
+        
     ####################################################
     # Add <theAdditionalOptions> values to args
     for add_opt in theAdditionalOptions:
@@ -913,6 +1005,18 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"):
             elif os.path.exists( "%s/%s.xml"%(d2, salomeappname) ):
                 dirs.append( d2 )
 
+    # Test
+    if cmd_opts.test_script_file is not None:
+        args[test_nam] = []
+        filename = cmd_opts.test_script_file
+        args[test_nam] += re.split( "[:;,]", filename )
+    # Play
+    if cmd_opts.play_script_file is not None:
+        args[play_nam] = []
+        filename = cmd_opts.play_script_file
+        args[play_nam] += re.split( "[:;,]", filename )
+
     # return arguments
     os.environ[config_var] = separator.join(dirs)
     #print "Args: ", args