#
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:
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)