Salome HOME
Merge branch 'V9_11_BR'
[modules/kernel.git] / bin / appli_gen.py
index b01e789b0e466a90a97d389c023be2c26c044562..1a190462f0c71e4748d0723734fe32a5c5dd81d6 100755 (executable)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python3
-# Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-## \file appli_gen.py
+# \file appli_gen.py
 #  Create a %SALOME application (virtual Salome installation)
 #
-usage = """%(prog)s [options]
-Typical use is:
-  python %(prog)s
-Typical use with options is:
-  python %(prog)s --verbose --prefix=<install directory> --config=<configuration file>
-"""
 
+import json
 import os
 import sys
 import shutil
@@ -39,15 +34,22 @@ import xml.sax
 import optparse
 import subprocess
 
+usage = """%(prog)s [options]
+Typical use is:
+  python %(prog)s
+Typical use with options is:
+  python %(prog)s --verbose --prefix=<install directory> --config=<configuration file>
+"""
+
 # --- names of tags in XML configuration file
-appli_tag   = "application"
-prereq_tag  = "prerequisites"
+appli_tag = "application"
+prereq_tag = "prerequisites"
 context_tag = "context"
 venv_directory_tag = "venv_directory"
 sha1_collect_tag = "sha1_collections"
-system_conf_tag  = "system_conf"
+system_conf_tag = "system_conf"
 modules_tag = "modules"
-module_tag  = "module"
+module_tag = "module"
 samples_tag = "samples"
 extra_tests_tag = "extra_tests"
 extra_test_tag = "extra_test"
@@ -57,17 +59,17 @@ env_module_tag = "env_module"
 python_tag = "python"
 
 # --- names of attributes in XML configuration file
-nam_att  = "name"
+nam_att = "name"
 path_att = "path"
-gui_att  = "gui"
+gui_att = "gui"
 version_att = "version"
-
 # -----------------------------------------------------------------------------
 
+
 # --- xml reader for SALOME application configuration file
 
 class xml_parser:
-    def __init__(self, fileName ):
+    def __init__(self, fileName):
         print("Configure parser: processing %s ..." % fileName)
         self.space = []
         self.config = {}
@@ -80,7 +82,7 @@ class xml_parser:
         parser.parse(fileName)
         pass
 
-    def boolValue( self, text):
+    def boolValue(self, text):
         if text in ("yes", "y", "1"):
             return 1
         elif text in ("no", "n", "0"):
@@ -302,6 +304,8 @@ def install(prefix, config_file, verbose=0):
     # In the same way as: module load [MODULE_LIST]
     env_modules = _config.get('env_modules', [])
     if env_modules:
+        with open(os.path.join(home_dir, 'env_modules.json'), 'w') as fd:
+            json.dump({"env_modules": env_modules}, fd)
         with open(os.path.join(home_dir, 'env.d', 'envModules.sh'), 'w') as fd:
             fd.write('#!/bin/bash\n')
             fd.write('module load %s\n' % (' '.join(env_modules)))
@@ -411,11 +415,11 @@ export LD_LIBRARY_PATH=${HOME}/${APPLI}/lib/salome:$LD_LIBRARY_PATH
         # Create environment for virtual env
         if venv_directory_path:
             command = """# SALOME venv Configuration
-export SALOME_VENV_DIRECTORY=%s
+export SALOME_VENV_DIRECTORY=${HOME}/${APPLI}/venv
 export PATH=${HOME}/${APPLI}/venv/bin:$PATH
 export LD_LIBRARY_PATH=${HOME}/${APPLI}/venv/lib:$LD_LIBRARY_PATH
 export PYTHONPATH=${HOME}/${APPLI}/venv/lib/python%s/site-packages
-""" % (venv_directory_path, versionPython)
+""" % (versionPython)
             f.write(command)
             pass
 
@@ -456,11 +460,11 @@ ADD_TO_LD_LIBRARY_PATH: ${HOME}/${APPLI}/lib/salome
         # Create environment for virtual env
         if venv_directory_path:
             command = """[SALOME venv Configuration]
-SALOME_VENV_DIRECTORY: %s
+SALOME_VENV_DIRECTORY: ${HOME}/${APPLI}/venv
 ADD_TO_PATH: ${HOME}/${APPLI}/venv/bin
 ADD_TO_LD_LIBRARY_PATH: ${HOME}/${APPLI}/venv/lib
 ADD_TO_PYTHONPATH: ${HOME}/${APPLI}/venv/lib/python%s/site-packages
-""" % (venv_directory_path, versionPython)
+""" % (versionPython)
             f.write(command)
             pass