]> SALOME platform Git repositories - modules/kernel.git/blob - bin/runSalomeOnDemand.py
Salome HOME
[bos #32522][EDF] SALOME on Demand. Added functions and refactored to support adding...
[modules/kernel.git] / bin / runSalomeOnDemand.py
1 #!/usr/bin/env python3
2 # -*- coding:utf-8 -*-
3 # Copyright (C) 2022  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
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.
9 #
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.
14 #
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
18 #
19 # See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 #  File   : runSalomeOnDemand.py
23 #  Author : Konstantin Leontev, Open Cascade
24 #
25 ## @package runSalomeOnDemand
26 # \brief Module that provides services to launch SALOME with custom set of modules
27 #
28
29 """Run SALOME app in the context of adding modules as extensions.
30 """
31
32 import os
33 import sys
34 import salomeContext
35 from SalomeOnDemandTK.extension_utilities import logger, \
36     DFILE_EXT, \
37     list_files_ext, set_selext_env, get_app_root
38
39
40 def set_ext_env(app_name='', version=''):
41     """
42     Set an environment to start SALOME as a set of extensions.
43
44     Args:
45         app_name - an application's name.
46         version - a version of an application.
47
48     Returns:
49         None.
50     """
51
52     logger.debug('Set an env for app: %s, version: %s...', app_name, version)
53
54     # Get the root directory
55     app_root = get_app_root()
56
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)
60     if not installed_ext:
61         logger.debug('There are not any extensions in %s!', app_root)
62         return
63
64     # Set the root dir as env variable
65     context = salomeContext.SalomeContext(None)
66     context.setVariable('SALOME_APPLICATION_DIR', app_root, overwrite=True)
67
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)
72
73         set_selext_env(app_root, ext_name, context)
74
75
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)
80     else:
81         logger.error('You must provide all the arguments!')
82         logger.info(set_ext_env.__doc__)