Salome HOME
venv directory is configured in config_appli.xml file
[modules/kernel.git] / bin / launchConfigureParser.py
old mode 100755 (executable)
new mode 100644 (file)
index afe6045..c7eb515
@@ -1,5 +1,5 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -70,6 +70,8 @@ valgrind_session_nam = "valgrind_session"
 shutdown_servers_nam = "shutdown_servers"
 foreground_nam = "foreground"
 wake_up_session_nam = "wake_up_session"
+launcher_only_nam = "launcher_only"
+launcher_nam = "launcher"
 
 # 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)
@@ -89,8 +91,9 @@ standalone_choices = [ "registry", "study", "moduleCatalog", "cppContainer"]
 
 # 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, shutdown_servers_nam )
+boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam, pinter_nam, shutdown_servers_nam, launcher_only_nam )
 intKeys = ( interp_nam, )
+strKeys = ( launcher_nam )
 
 # values of list type
 listKeys = ( embedded_nam, key_nam, modules_nam, standalone_nam, plugins_nam )
@@ -116,7 +119,7 @@ def version():
             match = re.search( r':\s+([a-zA-Z0-9.]+)\s*$', v )
             if match :
                 return match.group( 1 )
-    except:
+    except Exception:
         pass
     return ''
 
@@ -322,7 +325,7 @@ class xml_parser:
             else:
                 if isinstance( strloc, bytes):
                     strloc = strloc.decode().strip()
-        except:
+        except Exception:
             pass
         return strloc
 
@@ -365,6 +368,8 @@ class xml_parser:
                 self.opts[key] = self.boolValue( val )  # assign boolean value: 0 or 1
             elif nam in intKeys:
                 self.opts[key] = self.intValue( val )   # assign integer value
+            elif nam in strKeys:
+                self.opts[key] = val                    # assign value
             elif nam in listKeys:
                 self.opts[key] = [ self.strValue( a ) for a in re.split( "[:;,]", val ) ] # assign list value: []
             else:
@@ -430,7 +435,7 @@ class xml_parser:
                     pass
                 pass
             pass
-        except:
+        except Exception:
             if verbose(): print("Configure parser: Error : can not read configuration file %s" % absfname)
         pass
 
@@ -546,7 +551,7 @@ Python file arguments, if any, must be comma-separated (without blank characters
                       dest="gui",
                       help=help_str)
 
-    # Show Desktop (inly in GUI mode). Default: True
+    # Show Desktop (only 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."
@@ -683,6 +688,22 @@ Python file arguments, if any, must be comma-separated (without blank characters
                       dest="print_port",
                       help=help_str)
 
+    # launch only omniNames and Launcher server
+    help_str = "launch only omniNames and Launcher server"
+    pars.add_argument("--launcher_only",
+                      action="store_true",
+                      dest="launcher_only",
+                      help=help_str)
+
+    # machine and port where is the Launcher
+    help_str  = "machine and port where is the Launcher. Usage: "
+    help_str += "--launcher=machine:port"
+    pars.add_argument("--launcher",
+                      metavar="<=machine:port>",
+                      type=str,
+                      dest="launcher",
+                      help=help_str)
+
     # Do not relink ${HOME}/.omniORB_last.cfg
     help_str = "Do not save current configuration ${HOME}/.omniORB_last.cfg"
     pars.add_argument("--nosave-config",
@@ -764,10 +785,10 @@ Python file arguments, if any, must be comma-separated (without blank characters
     # 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. "
+    help_str += "If this variable is not set, the last configuration is taken. "
     pars.add_argument("--wake-up-session",
                       action="store_true",
-                      dest="wake_up_session",
+                      dest="wake_up_session", default=False,
                       help=help_str)
 
     # server launch mode
@@ -811,7 +832,7 @@ Python file arguments, if any, must be comma-separated (without blank characters
 args = {}
 #def get_env():
 #args = []
-def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
+def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None, keepEnvironment=True):
     ###
     # Collect launch configuration files:
     # - The environment variable "<appname>Config" (SalomeAppConfig) which can
@@ -825,7 +846,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
     # - 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
+    #   is found in the next analyzed configuration 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)
@@ -833,7 +854,6 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
     # - Command line options have the highest priority and replace options
     #   specified in configuration file(s)
     ###
-
     global args
     config_var = appname+'Config'
 
@@ -875,25 +895,24 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
         else:
             dirs += re.split('[;|:]', os.getenv(config_var))
 
-    gui_available = False
-    if os.getenv("GUI_ROOT_DIR"):
-        gui_resources_dir = os.path.join(os.getenv("GUI_ROOT_DIR"),'share','salome','resources','gui')
-        if os.path.isdir(gui_resources_dir):
-            gui_available = True
-            dirs.append(gui_resources_dir)
-        pass
-    if not gui_available:
-        kernel_resources_dir = os.path.join(os.getenv("KERNEL_ROOT_DIR"),'bin','salome','appliskel')
-        if os.getenv("KERNEL_ROOT_DIR") and os.path.isdir( kernel_resources_dir ):
-          dirs.append(kernel_resources_dir)
-        pass
-    os.environ[config_var] = os.pathsep.join(dirs)
+    if not keepEnvironment:
+        if os.getenv("GUI_ROOT_DIR") and os.path.isdir(os.getenv("GUI_ROOT_DIR")):
+            gui_resources_dir = os.path.join(os.getenv("GUI_ROOT_DIR"),'share','salome','resources','gui')
+            if os.path.isdir(gui_resources_dir):
+                dirs.append(gui_resources_dir)
+            pass
+        else:
+            kernel_resources_dir = os.path.join(os.getenv("KERNEL_ROOT_DIR"),'bin','salome','appliskel')
+            if os.getenv("KERNEL_ROOT_DIR") and os.path.isdir( kernel_resources_dir ):
+              dirs.append(kernel_resources_dir)
+            pass
+        os.environ[config_var] = os.pathsep.join(dirs)
 
     dirs.reverse() # reverse order, like in "path" variable - FILO-style processing
 
     try:
         dirs.remove('') # to remove empty dirs if the variable terminate by ":" or if there are "::" inside
-    except:
+    except Exception:
         pass
 
     _opts = {} # associative array of options to be filled
@@ -907,7 +926,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
             try:
                 p = xml_parser(filename, _opts, [])
                 _opts = p.opts
-            except:
+            except Exception:
                 if verbose(): print("Configure parser: Error : can not read configuration file %s" % filename)
             pass
 
@@ -925,7 +944,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
         try:
             p = xml_parser(user_config, _opts, [])
             _opts = p.opts
-        except:
+        except Exception:
             if verbose(): print('Configure parser: Error : can not read user configuration file')
             user_config = ""
 
@@ -972,7 +991,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
     if cmd_opts.batch is not None:
         args[batch_nam] = True
 
-    if not gui_available:
+    if not os.getenv("GUI_ROOT_DIR") or not os.path.isdir(os.getenv("GUI_ROOT_DIR")):
         args[gui_nam] = False
 
     if args[gui_nam]:
@@ -1010,7 +1029,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
     if args[gui_nam] and args["session_gui"]:
         new_args = []
         for sa_obj in args[script_nam]:  # args[script_nam] is a list of ScriptAndArgs objects
-            script = re.sub(r'^python.*\s+', r'', sa_obj.script)
+            script = re.sub(r'^python. *\s+', r'', sa_obj.script)
             new_args.append(ScriptAndArgs(script=script, args=sa_obj.args, out=sa_obj.out))
         #
         args[script_nam] = new_args
@@ -1087,6 +1106,14 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
         args[shutdown_servers_nam] = cmd_opts.shutdown_servers
         pass
 
+    # Launcher only
+    if cmd_opts.launcher_only is not None:
+        args[launcher_only_nam] = cmd_opts.launcher_only
+
+    # machine and port where is the Launcher
+    if cmd_opts.launcher is not None:
+        args[launcher_nam] = cmd_opts.launcher
+
     # Foreground
     if cmd_opts.foreground is None:
         args[foreground_nam] = 1
@@ -1156,6 +1183,8 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None):
         args[lang_nam] = cmd_opts.language
 
     # return arguments
-    os.environ[config_var] = os.pathsep.join(dirs)
+    if not keepEnvironment:
+        os.environ[config_var] = os.pathsep.join(dirs)
+
     # print("Args: ", args)
     return args