Salome HOME
New params in config_appli to handle environment modules
authorGilles DAVID <gilles-g.david@edf.fr>
Thu, 14 Sep 2017 15:36:27 +0000 (17:36 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Thu, 14 Sep 2017 17:19:01 +0000 (19:19 +0200)
Usage of --with-env-modules in new salome wrapper

bin/appli_gen.py [changed mode: 0644->0755]
bin/appliskel/.salome_run [new file with mode: 0755]
bin/appliskel/salome

old mode 100644 (file)
new mode 100755 (executable)
index 4e04d1d..7dc3e89
@@ -51,6 +51,8 @@ samples_tag = "samples"
 extra_tests_tag = "extra_tests"
 extra_test_tag = "extra_test"
 resources_tag = "resources"
+env_modules_tag = "env_modules"
+env_module_tag = "env_module"
 
 # --- names of attributes in XML configuration file
 nam_att  = "name"
@@ -69,6 +71,7 @@ class xml_parser:
         self.config["modules"] = []
         self.config["guimodules"] = []
         self.config["extra_tests"] = []
+        self.config["env_modules"] = []
         parser = xml.sax.make_parser()
         parser.setContentHandler(self)
         parser.parse(fileName)
@@ -126,6 +129,12 @@ class xml_parser:
                 self.config["guimodules"].append(nam)
                 pass
             pass
+        # --- if we are analyzing "env_module" element then store its "name" attribute
+        elif self.space == [appli_tag, env_modules_tag, env_module_tag] and \
+                nam_att in attrs.getNames():
+            nam = attrs.getValue( nam_att )
+            self.config["env_modules"].append(nam)
+            pass
         # --- if we are analyzing "extra_test" element then store its "name" and "path" attributes
         elif self.space == [appli_tag,extra_tests_tag,extra_test_tag] and \
             nam_att in attrs.getNames() and \
@@ -190,8 +199,9 @@ def install(prefix, config_file, verbose=0):
         print inst.args
         print "Configure parser: error in configuration file %s" % filename
         pass
-    except:
+    except Exception as e:
         print "Configure parser: Error : can not read configuration file %s, check existence and rights" % filename
+        print(e)
         pass
 
     if verbose:
@@ -244,7 +254,7 @@ def install(prefix, config_file, verbose=0):
                'getAppliPath.py',
                'kill_remote_containers.py',
                'runRemote.sh',
-               'salome',
+               '.salome_run',
                'update_catalogs.py',
                '.bashrc',
                ):
@@ -256,6 +266,19 @@ def install(prefix, config_file, verbose=0):
         pass
 
 
+    # Copy salome script 
+    salome_script = open(os.path.join(appliskel_dir, "salome")).read()
+    salome_file = os.path.join(home_dir, "salome")
+    try:
+        os.remove(salome_file)
+    except:
+        pass
+    env_modules = [m.encode('utf8') for m in _config.get('env_modules', [])]
+    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"))
diff --git a/bin/appliskel/.salome_run b/bin/appliskel/.salome_run
new file mode 100755 (executable)
index 0000000..171036b
--- /dev/null
@@ -0,0 +1,73 @@
+#! /usr/bin/env python
+
+# Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import os
+import sys
+
+def main(args):
+  # Identify application path then locate configuration files
+  currentPath = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
+  launcherFile = os.path.basename(__file__)
+  from salome_starter import initialize
+  initialize(currentPath, launcherFile)
+
+  if len(args) == 1 and args[0] in ['--help', 'help', '-h', '--h']:
+    from salomeContext import usage
+    usage()
+    sys.exit(0)
+
+  from salomeContextUtils import getConfigFileNames
+  configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True)
+
+  if len(unexisting) > 0:
+    print "ERROR: unexisting configuration/environment file(s): " + ', '.join(unexisting)
+    sys.exit(1)
+
+  # Create a SalomeContext which parses configFileNames to initialize environment
+  from salomeContextUtils import SalomeContextException
+  try:
+    from salomeContext import SalomeContext
+    context = SalomeContext(configFileNames)
+
+    # Here set specific variables, if needed
+    # context.addToPath('mypath')
+    # context.addToLdLibraryPath('myldlibrarypath')
+    # context.addToPythonPath('mypythonpath')
+    # context.setVariable('myvarname', 'value')
+
+    # Start SALOME, parsing command line arguments
+    out, err, returncode = context.runSalome(args)
+    if out:
+      sys.stdout.write(out)
+    if err:
+      sys.stderr.write(err)
+    #print 'Thank you for using SALOME!'
+    sys.exit(returncode)
+  except SalomeContextException, e:
+    import logging
+    logging.getLogger("salome").error(e)
+    sys.exit(1)
+#
+
+if __name__ == "__main__":
+  args = sys.argv[1:]
+  main(args)
+#
index 171036b0e1e041a36aa0069af4c5490c113e907a..b8b43e800f505ecc2a3c53c390a0c23ad420533e 100755 (executable)
@@ -1,73 +1,32 @@
 #! /usr/bin/env python
 
-# Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
 import os
+import subprocess
 import sys
 
-def main(args):
-  # Identify application path then locate configuration files
-  currentPath = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
-  launcherFile = os.path.basename(__file__)
-  from salome_starter import initialize
-  initialize(currentPath, launcherFile)
-
-  if len(args) == 1 and args[0] in ['--help', 'help', '-h', '--h']:
-    from salomeContext import usage
-    usage()
-    sys.exit(0)
-
-  from salomeContextUtils import getConfigFileNames
-  configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True)
-
-  if len(unexisting) > 0:
-    print "ERROR: unexisting configuration/environment file(s): " + ', '.join(unexisting)
-    sys.exit(1)
-
-  # Create a SalomeContext which parses configFileNames to initialize environment
-  from salomeContextUtils import SalomeContextException
-  try:
-    from salomeContext import SalomeContext
-    context = SalomeContext(configFileNames)
+MODULES = []
 
-    # Here set specific variables, if needed
-    # context.addToPath('mypath')
-    # context.addToLdLibraryPath('myldlibrarypath')
-    # context.addToPythonPath('mypythonpath')
-    # context.setVariable('myvarname', 'value')
 
-    # Start SALOME, parsing command line arguments
-    out, err, returncode = context.runSalome(args)
-    if out:
-      sys.stdout.write(out)
-    if err:
-      sys.stderr.write(err)
-    #print 'Thank you for using SALOME!'
-    sys.exit(returncode)
-  except SalomeContextException, e:
-    import logging
-    logging.getLogger("salome").error(e)
-    sys.exit(1)
-#
+def main(args):
+    ''' Load modules then launch salome
+    '''
+    if MODULES:
+        env_modules = 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:
+          env_modules += env_modules_l[-1][len(env_modules_option):].split(',')
+          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)
+
+    currentPath = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
+    proc = subprocess.Popen(['./.salome_run'] + args,
+                            close_fds=True, cwd=currentPath)
+    out, err = proc.communicate()
+    return out, err, proc.returncode
 
 if __name__ == "__main__":
-  args = sys.argv[1:]
-  main(args)
+    main(sys.argv[1:])
 #
+