3 # Copyright (C) 2022 CEA/DEN, EDF R&D, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # File : runSalomeOnDemand.py
23 # Author : Konstantin Leontev, Open Cascade
25 ## @package runSalomeOnDemand
26 # \brief Module that provides services to launch SALOME with custom set of modules
29 """Run SALOME app in the context of adding modules as extensions.
35 from SalomeOnDemandTK.extension_utilities import logger, \
37 list_files_ext, set_selext_env, get_app_root
40 def set_ext_env(app_name='', version=''):
42 Set an environment to start SALOME as a set of extensions.
45 app_name - an application's name.
46 version - a version of an application.
52 logger.debug('Set an env for app: %s, version: %s...', app_name, version)
54 # Get the root directory
55 app_root = get_app_root()
57 # Find and source all _env.py files for installed extensions
58 installed_ext = list_files_ext(app_root, DFILE_EXT)
59 logger.debug('Installed extensions: %s', installed_ext)
61 logger.debug('There are not any extensions in %s!', app_root)
64 # Set the root dir as env variable
65 context = salomeContext.SalomeContext(None)
66 context.setVariable('SALOME_APPLICATION_DIR', app_root, overwrite=True)
68 # Execute env file as a module
69 for salomexd in installed_ext:
70 salomexd_name = os.path.basename(salomexd)
71 ext_name, _ = os.path.splitext(salomexd_name)
73 set_selext_env(app_root, ext_name, context)
76 if __name__ == "__main__":
77 if len(sys.argv) == 3:
78 arg_1, arg_2 = sys.argv[1:]
79 set_ext_env(arg_1, arg_2)
81 logger.error('You must provide all the arguments!')
82 logger.info(set_ext_env.__doc__)