"""
Add a custom environment to the SALOME extension.
"""
+
+import os
+
+
+def init(context, root_dir):
+ """
+ Set an environment for an extension on start of SALOME app.
+
+ Args:
+ context - an SalomeContext object.
+ root_dir - a path to __SALOME_EXT__ directory.
+
+ Returns:
+ None.
+ """
+
+ python_version = '3.10'
+ python_libdir = os.path.join('lib', 'python' + python_version, 'site-packages')
+
+ reinitialise_paths = True
+
+ #[KERNEL]
+ kernel_root_dir = os.path.join(root_dir, 'KERNEL')
+ context.setVariable('KERNEL_ROOT_DIR', kernel_root_dir, overwrite=True)
+ context.addToPath(os.path.join(kernel_root_dir, 'bin', 'salome'))
+ context.addToLdLibraryPath(os.path.join(kernel_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(kernel_root_dir, 'bin', 'salome'))
+ context.addToPythonPath(os.path.join(kernel_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(kernel_root_dir, python_libdir, 'salome'))
+
+ #[GUI]
+ gui_root_dir = os.path.join(root_dir, 'GUI')
+ context.setVariable('GUI_ROOT_DIR', gui_root_dir, overwrite=True)
+ context.addToPath(os.path.join(gui_root_dir, 'bin', 'salome'))
+ context.addToLdLibraryPath(os.path.join(gui_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(gui_root_dir, 'bin', 'salome'))
+ context.addToPythonPath(os.path.join(gui_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(gui_root_dir, python_libdir, 'salome'))
+
+ gui_res_dir = os.path.join(gui_root_dir, 'share', 'salome', 'resources', 'gui')
+ if reinitialise_paths:
+ context.setVariable('SalomeAppConfig', gui_res_dir, overwrite=True)
+ else:
+ context.addToPath('SalomeAppConfig', gui_res_dir, separator=':')
"""
Add a custom environment to the SALOME extension.
"""
+
+import os
+
+
+def init(context, root_dir):
+ """
+ Set an environment for an extension on start of SALOME app.
+
+ Args:
+ context - an SalomeContext object.
+ root_dir - a path to __SALOME_EXT__ directory.
+
+ Returns:
+ None.
+ """
+
+ python_version = '3.10'
+ python_libdir = os.path.join('lib', 'python' + python_version, 'site-packages')
+
+ #[GEOM]
+ geom_root_dir = os.path.join(root_dir, 'GEOM')
+ context.setVariable('GEOM_ROOT_DIR', geom_root_dir, overwrite=True)
+ context.addToPath(os.path.join(geom_root_dir, 'bin', 'salome'))
+ context.addToLdLibraryPath(os.path.join(geom_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(geom_root_dir, 'bin', 'salome'))
+ context.addToPythonPath(os.path.join(geom_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(geom_root_dir, python_libdir, 'salome'))
+
+ context.setVariable('PARALLEL_VISU', '1', overwrite=True)
+
+ geom_res_dir = os.path.join(geom_root_dir, 'share', 'salome', 'resources', 'geom')
+ context.addToPath('SalomeAppConfig', geom_res_dir, separator=':')
+ context.setVariable('GEOM_PluginsList',
+ 'BREPPlugin:STEPPlugin:IGESPlugin:STLPlugin:XAOPlugin:VTKPlugin:AdvancedGEOM',
+ overwrite=True)
+ context.setVariable('CSF_ShHealingDefaults', geom_res_dir, overwrite=True)
"""
Add a custom environment to the SALOME extension.
"""
+
+import os
+
+
+def init(context, root_dir):
+ """
+ Set an environment for an extension on start of SALOME app.
+
+ Args:
+ context - an SalomeContext object.
+ root_dir - a path to __SALOME_EXT__ directory.
+
+ Returns:
+ None.
+ """
+
+ python_version = '3.10'
+ python_libdir = os.path.join('lib', 'python' + python_version, 'site-packages')
+
+ #[PYHELLO]
+ pyhello_root_dir = os.path.join(root_dir, 'PYHELLO')
+ context.setVariable('PYHELLO_ROOT_DIR', pyhello_root_dir, overwrite=True)
+ context.addToPath(os.path.join(pyhello_root_dir, 'bin', 'salome'))
+ context.addToLdLibraryPath(os.path.join(pyhello_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(pyhello_root_dir, 'bin', 'salome'))
+ context.addToPythonPath(os.path.join(pyhello_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(pyhello_root_dir, python_libdir, 'salome'))
+ context.addToPath('SALOME_MODULES', 'PYHELLO', separator=',')
+
+ pyhello_res_dir = os.path.join(pyhello_root_dir, 'share', 'salome', 'resources', 'pyhello')
+ context.addToPath('SalomeAppConfig', pyhello_res_dir, separator=':')
"""
Add a custom environment to the SALOME extension.
"""
+
+import os
+
+
+def init(context, root_dir):
+ """
+ Set an environment for an extension on start of SALOME app.
+
+ Args:
+ context - an SalomeContext object.
+ root_dir - a path to __SALOME_EXT__ directory.
+
+ Returns:
+ None.
+ """
+
+ python_version = '3.10'
+ python_libdir = os.path.join('lib', 'python' + python_version, 'site-packages')
+
+ reinitialise_paths = True
+
+ #[SMESH]
+ smesh_root_dir = os.path.join(root_dir, 'SMESH')
+ context.setVariable('SMESH_ROOT_DIR', smesh_root_dir, overwrite=True)
+ context.addToPath(os.path.join(smesh_root_dir, 'bin', 'salome'))
+ context.addToLdLibraryPath(os.path.join(smesh_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(smesh_root_dir, 'bin', 'salome'))
+ context.addToPythonPath(os.path.join(smesh_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(smesh_root_dir, python_libdir, 'salome'))
+ if reinitialise_paths:
+ context.setVariable('SMESH_MeshersList', 'StdMeshers', overwrite=True)
+ else:
+ context.addToVariable('SMESH_MeshersList', 'StdMeshers', separator=':')
+
+ smesh_res_dir = os.path.join(smesh_root_dir, 'share', 'salome', 'resources', 'smesh')
+ context.addToPath('SalomeAppConfig', smesh_res_dir, separator=':')
+
+ #[gmsh]
+ gmsh_root_dir = os.path.join(root_dir, 'gmsh')
+ context.setVariable('GMSHHOME', gmsh_root_dir, overwrite=True)
+ context.setVariable('GMSH_ROOT_DIR', gmsh_root_dir, overwrite=True)
+ context.addToLdLibraryPath(os.path.join(gmsh_root_dir, 'lib'))
+
+ #[NETGENPLUGIN]
+ netgenplugin_root_dir = os.path.join(root_dir, 'NETGENPLUGIN')
+ context.setVariable('NETGENPLUGIN_ROOT_DIR', netgenplugin_root_dir, overwrite=True)
+ context.addToPath(os.path.join(netgenplugin_root_dir, 'bin', 'salome'))
+ context.addToLdLibraryPath(os.path.join(netgenplugin_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(netgenplugin_root_dir, 'bin', 'salome'))
+ context.addToPythonPath(os.path.join(netgenplugin_root_dir, 'lib', 'salome'))
+ context.addToPythonPath(os.path.join(netgenplugin_root_dir, python_libdir, 'salome'))
+ context.addToVariable('SMESH_MeshersList', 'NETGENPlugin', separator=':')
+
+ netgenplugin_res_dir = os.path.join(netgenplugin_root_dir,
+ 'share', 'salome', 'resources', 'netgenplugin')
+ context.addToPath('SalomeAppConfig', netgenplugin_res_dir, separator=':')
--- /dev/null
+#!/usr/bin/env python3
+# -*- coding:utf-8 -*-
+# Copyright (C) 2022 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 https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+# File : runSalomeOnDemand.py
+# Author : Konstantin Leontev, Open Cascade
+#
+## @package runSalomeOnDemand
+# \brief Module that provides services to launch SALOME with custom set of modules
+#
+
+"""Run SALOME app in the context of adding modules as extensions.
+"""
+
+import os
+import sys
+import importlib.util
+from pathlib import Path
+import runSalome
+import salomeContext
+from SalomeOnDemandTK.extension_utilities import logger, \
+ DFILE_EXT, SALOME_EXTDIR, \
+ list_files_ext, find_envpy
+
+
+def module_from_filename(filename):
+ """
+ Create and execute a module by filename.
+
+ Args:
+ filename - a given python filename.
+
+ Returns:
+ Module.
+ """
+
+ # Get the module from the filename
+ basename = os.path.basename(filename)
+ module_name, _ = os.path.splitext(basename)
+
+ spec = importlib.util.spec_from_file_location(module_name, filename)
+ if not spec:
+ logger.error('Could not get a spec for %s file!')
+ return None
+
+ module = importlib.util.module_from_spec(spec)
+ if not module:
+ logger.error('Could not get a module for %s file!')
+ return None
+
+ sys.modules[module_name] = module
+
+ logger.debug('Execute %s module', module_name)
+ spec.loader.exec_module(module)
+
+ return module
+
+
+def set_ext_env(app_name, version):
+ """
+ Set an environment to start SALOME as a set of extensions.
+
+ Args:
+ app_name - an application's name.
+ version - a version of an application.
+
+ Returns:
+ None.
+ """
+
+ logger.debug('Set an env for app: %s, version: %s...', app_name, version)
+
+ # Get the root directory
+ levels_up = 2
+ app_root = str(Path(__file__).resolve().parents[levels_up - 1])
+ logger.debug('App root: %s', app_root)
+
+ # Find and source all _env.py files for installed extensions
+ installed_ext = list_files_ext(app_root, DFILE_EXT)
+ logger.debug('Installed extensions: %s', installed_ext)
+ if not installed_ext:
+ logger.debug('There are not any extensions in %s!', app_root)
+ return
+
+ # Execute env file as a module
+ context = salomeContext.SalomeContext(None)
+ ext_root = os.path.join(app_root, SALOME_EXTDIR)
+ for salomexd in installed_ext:
+ salomexd_name = os.path.basename(salomexd)
+ ext_name, _ = os.path.splitext(salomexd_name)
+
+ # Find env file
+ ext_envpy = find_envpy(app_root, ext_name)
+ if not ext_envpy:
+ continue
+
+ # Get a module
+ envpy_module = module_from_filename(ext_envpy)
+ if not envpy_module:
+ continue
+
+ # Set env if we have something to set
+ if hasattr(envpy_module, 'init'):
+ envpy_module.init(context, ext_root)
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 3:
+ arg_1, arg_2 = sys.argv[1:] # pylint: disable=unbalanced-tuple-unpacking
+ set_ext_env(arg_1, arg_2)
+
+ runSalome.runSalome()
+ else:
+ logger.error('You must provide all the arguments!')
+ logger.info(set_ext_env.__doc__)