From 97b8a51943a7412d4a9c8c665214ed67bd72298c Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Thu, 14 Sep 2017 17:36:27 +0200 Subject: [PATCH] New params in config_appli to handle environment modules Usage of --with-env-modules in new salome wrapper --- bin/appli_gen.py | 27 ++++++++++++- bin/appliskel/.salome_run | 73 +++++++++++++++++++++++++++++++++ bin/appliskel/salome | 85 ++++++++++----------------------------- 3 files changed, 120 insertions(+), 65 deletions(-) mode change 100644 => 100755 bin/appli_gen.py create mode 100755 bin/appliskel/.salome_run diff --git a/bin/appli_gen.py b/bin/appli_gen.py old mode 100644 new mode 100755 index 4e04d1d32..7dc3e8987 --- a/bin/appli_gen.py +++ b/bin/appli_gen.py @@ -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 index 000000000..171036b0e --- /dev/null +++ b/bin/appliskel/.salome_run @@ -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) +# diff --git a/bin/appliskel/salome b/bin/appliskel/salome index 171036b0e..b8b43e800 100755 --- a/bin/appliskel/salome +++ b/bin/appliskel/salome @@ -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:]) # + -- 2.39.2