Salome HOME
[EDF29322] Take into account SALOME_APPLI_OPTIONS as a second way to pilot argument...
authorGilles DAVID <gilles-g.david@edf.fr>
Wed, 7 Feb 2024 13:08:58 +0000 (14:08 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 7 Feb 2024 15:15:23 +0000 (16:15 +0100)
bin/appliskel/salome_common.py

index 1cb1738e12e3c5f2f645bfe4747efa69f0646051..fdcbd6f5dfca68b4448607078ee1be93d20ae8ed 100644 (file)
 #
 
 import json
+import logging
 import os
 import subprocess
 import sys
+from pathlib import Path
+
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
 
 
 def main(args):
     ''' Load modules then launch salome
     '''
-    appliPath = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
-    MODULES_FILE = os.path.join(appliPath, "env_modules.json")
-    if os.path.isfile(MODULES_FILE):
-        env_modules = json.loads(open(MODULES_FILE).read()).get('env_modules')
+    appliPath = Path(__file__).parent.resolve()
+    modules_file = appliPath / "env_modules.json"
+    if modules_file.is_file():
+        env_modules = json.loads(open(modules_file).read()).get('env_modules', [])
         env_modules_option = "--with-env-modules="
         env_modules_l = [x for x in args if x.startswith(env_modules_option)]
         if env_modules_l:
@@ -38,8 +43,23 @@ def main(args):
             args = [x for x in args if not x.startswith(env_modules_option)]
         env_modules_option += "%s" % ','.join(env_modules)
         args.append(env_modules_option)
+    
+    salome_appli_options = os.environ.get("SALOME_APPLI_OPTIONS")
+    if salome_appli_options:
+        command = ""
+        options = []
+        if args:
+            command = args[0]
+            options = args[1:] if len(args) > 1 else []
+        args = []
+        if command:
+            args.append(command)
+        args = args + salome_appli_options.split() + options
+    
+    logger.debug(f"args: {args}")
 
-    os.environ["ROOT_SALOME_INSTALL"] = appliPath
-    proc = subprocess.Popen([os.path.join(appliPath, '.salome_run')] + args, close_fds=True)
+    os.environ["ROOT_SALOME_INSTALL"] = f"{appliPath}"
+    salome_run_script = appliPath / '.salome_run'
+    proc = subprocess.Popen([f"{salome_run_script}"] + args, close_fds=True)
     out, err = proc.communicate()
     sys.exit(proc.returncode)