Salome HOME
The list of env_modules is stored in a json file
authorGilles DAVID <gilles-g.david@edf.fr>
Thu, 17 Nov 2022 09:22:49 +0000 (10:22 +0100)
committerGilles DAVID <gilles-g.david@edf.fr>
Thu, 17 Nov 2022 09:25:55 +0000 (10:25 +0100)
bin/appli_gen.py
bin/appliskel/salome_common.py

index 0a4e06be391ddc83c653e1282d19f33f471fb4ab..269573403290573ea7c11368138a966a1289bfc8 100755 (executable)
 # 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"):
@@ -281,6 +283,9 @@ def install(prefix, config_file, verbose=0):
                'runRemote.sh',
                'runRemoteSSL.sh',
                '.salome_run',
+               'salome',
+               'salome_mesa',
+               'salome_common.py',
                'update_catalogs.py',
                '.bashrc',
                ):
@@ -302,23 +307,12 @@ 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)))
 
-    # Copy salome / salome_mesa scripts:
-
-    for scripts in ('salome', 'salome_mesa', 'salome_common.py'):
-        salome_script = open(os.path.join(appliskel_dir, scripts)).read()
-        salome_file = os.path.join(home_dir, scripts)
-        try:
-            os.remove(salome_file)
-        except Exception:
-            pass
-        with open(salome_file, 'w') as fd:
-            fd.write(salome_script.replace('MODULES = []', 'MODULES = {}'.format(env_modules)))
-            os.chmod(salome_file, 0o755)
-
     # Add .salome-completion.sh file
     shutil.copyfile(os.path.join(appliskel_dir, ".salome-completion.sh"),
                     os.path.join(home_dir, ".salome-completion.sh"))
index 119103804f5fff6d494e4e776566c50bdada0afb..65d6b525b1b3fdaaf0d7671957ffc514c8a63499 100644 (file)
@@ -1,4 +1,4 @@
-    #! /usr/bin/env python3
+#! /usr/bin/env python3
 # Copyright (C) 2021-2022  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+import json
 import os
 import subprocess
 import sys
 
-MODULES = []
-
 
 def main(args):
     ''' Load modules then launch salome
     '''
-    if MODULES:
-        env_modules = MODULES[:]
+    appliPath = os.path.dirname(os.path.realpath(__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')
         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 +39,7 @@ def main(args):
         env_modules_option += "%s" % ','.join(env_modules)
         args.append(env_modules_option)
 
-    appliPath = os.path.dirname(os.path.realpath(__file__))
-    os.environ["ROOT_SALOME_INSTALL"]=appliPath
+    os.environ["ROOT_SALOME_INSTALL"] = appliPath
     proc = subprocess.Popen([os.path.join(appliPath, '.salome_run')] + args, close_fds=True)
     out, err = proc.communicate()
     sys.exit(proc.returncode)