From: Konstantin Leontev Date: Thu, 22 Dec 2022 14:18:57 +0000 (+0300) Subject: [bos #32522][EDF] SALOME on Demand. Added starting salome with only installed on... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ba220d2bc45d9159683bba9983a80ac1775c9cd0;p=modules%2Fkernel.git [bos #32522][EDF] SALOME on Demand. Added starting salome with only installed on demand extensions if arg on_demand=1. Changed log formatting because of doubled lines in logs. --- diff --git a/bin/SalomeOnDemandTK/Base_env.py b/bin/SalomeOnDemandTK/Base_env.py index 98f7a564c..db19eb288 100644 --- a/bin/SalomeOnDemandTK/Base_env.py +++ b/bin/SalomeOnDemandTK/Base_env.py @@ -47,4 +47,4 @@ def init(context, root_dir): if reinitialise_paths: context.setVariable('SalomeAppConfig', gui_res_dir, overwrite=True) else: - context.addToPath('SalomeAppConfig', gui_res_dir, separator=':') + context.addToVariable('SalomeAppConfig', gui_res_dir, separator=':') diff --git a/bin/SalomeOnDemandTK/GEOM_env.py b/bin/SalomeOnDemandTK/GEOM_env.py index b08b07357..7912bbf87 100644 --- a/bin/SalomeOnDemandTK/GEOM_env.py +++ b/bin/SalomeOnDemandTK/GEOM_env.py @@ -35,7 +35,7 @@ def init(context, root_dir): 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.addToVariable('SalomeAppConfig', geom_res_dir, separator=':') context.setVariable('GEOM_PluginsList', 'BREPPlugin:STEPPlugin:IGESPlugin:STLPlugin:XAOPlugin:VTKPlugin:AdvancedGEOM', overwrite=True) diff --git a/bin/SalomeOnDemandTK/PYHELLO_env.py b/bin/SalomeOnDemandTK/PYHELLO_env.py index 7e23aacc0..0fa078813 100644 --- a/bin/SalomeOnDemandTK/PYHELLO_env.py +++ b/bin/SalomeOnDemandTK/PYHELLO_env.py @@ -31,7 +31,7 @@ def init(context, root_dir): 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=',') + context.addToVariable('SALOME_MODULES', 'PYHELLO', separator=',') pyhello_res_dir = os.path.join(pyhello_root_dir, 'share', 'salome', 'resources', 'pyhello') - context.addToPath('SalomeAppConfig', pyhello_res_dir, separator=':') + context.addToVariable('SalomeAppConfig', pyhello_res_dir, separator=':') diff --git a/bin/SalomeOnDemandTK/SMESH_and_plugins_env.py b/bin/SalomeOnDemandTK/SMESH_and_plugins_env.py index 26cd9a150..10cde6887 100644 --- a/bin/SalomeOnDemandTK/SMESH_and_plugins_env.py +++ b/bin/SalomeOnDemandTK/SMESH_and_plugins_env.py @@ -39,7 +39,7 @@ def init(context, root_dir): 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=':') + context.addToVariable('SalomeAppConfig', smesh_res_dir, separator=':') #[gmsh] gmsh_root_dir = os.path.join(root_dir, 'gmsh') @@ -59,4 +59,4 @@ def init(context, root_dir): netgenplugin_res_dir = os.path.join(netgenplugin_root_dir, 'share', 'salome', 'resources', 'netgenplugin') - context.addToPath('SalomeAppConfig', netgenplugin_res_dir, separator=':') + context.addToVariable('SalomeAppConfig', netgenplugin_res_dir, separator=':') diff --git a/bin/SalomeOnDemandTK/extension_utilities.py b/bin/SalomeOnDemandTK/extension_utilities.py index ebfa9c519..f60c80efd 100644 --- a/bin/SalomeOnDemandTK/extension_utilities.py +++ b/bin/SalomeOnDemandTK/extension_utilities.py @@ -37,9 +37,6 @@ import logging import json from traceback import format_exc -# Setup logger's output -FORMAT = '%(funcName)s():%(lineno)s: %(message)s' -logging.basicConfig(format=FORMAT, level=logging.DEBUG) logger = logging.getLogger() SALOME_EXTDIR = '__SALOME_EXT__' diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 42c90e6f4..fde036288 100644 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -85,6 +85,7 @@ salomecfgname = "salome" salomeappname = "SalomeApp" script_nam = "pyscript" verbosity_nam = "verbosity" +on_demand_nam = "on_demand" # possible choices for the "embedded" and "standalone" parameters embedded_choices = [ "registry", "study", "moduleCatalog", "cppContainer", "SalomeAppEngine" ] @@ -92,7 +93,7 @@ standalone_choices = [ "registry", "study", "moduleCatalog", "cppContainer"] # values of boolean type (must be '0' or '1'). # xml_parser.boolValue() is used for correct setting -boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam, pinter_nam, shutdown_servers_nam, launcher_only_nam ) +boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam, pinter_nam, shutdown_servers_nam, launcher_only_nam, on_demand_nam ) intKeys = ( interp_nam, ) strKeys = ( launcher_nam ) @@ -827,6 +828,17 @@ Python file arguments, if any, must be comma-separated (without blank characters default="0", help=help_str) + # On demand + help_str = "Use installed salome on-demand extensions." + help_str += "0 to run without salome extensions [default], " + help_str += "1 to run only installed salome extensions. " + pars.add_argument("--on-demand", + dest="on_demand", + metavar="<0/1>", + action=StoreBooleanAction, + default=False, + help=help_str) + # Positional arguments (hdf file, python file) pars.add_argument("arguments", nargs=argparse.REMAINDER) @@ -1046,6 +1058,7 @@ def get_env(appname=salomeappname, cfgname=salomecfgname, exeName=None, keepEnvi args[script_nam] = new_args args[verbosity_nam] = cmd_opts.verbosity + args[on_demand_nam] = cmd_opts.on_demand # xterm if cmd_opts.xterm is not None: diff --git a/bin/runSalome.py b/bin/runSalome.py index eb6fa9a1b..6094707b4 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -33,6 +33,8 @@ from salomeContextUtils import ScriptAndArgsObjectEncoder import runSalomeNoServer import runSalomeCommon import platform +import runSalomeOnDemand +from launchConfigureParser import verbosity_nam, on_demand_nam import logging logger = logging.getLogger() @@ -81,7 +83,7 @@ def startSalome(args, modules_list, modules_root_dir): mySessionServ.run() ior_fakens_filename = mySessionServ.iorfakens logger.debug("Rendez-vous file for to retrieve IOR of session is \"{}\"".format(ior_fakens_filename)) - + end_time = os.times() # @@ -175,9 +177,15 @@ def main(exeName=None): """Salome launch as a main application""" keep_env = not os.getenv('SALOME_PLEASE_SETUP_ENVIRONMENT_AS_BEFORE') args, modules_list, modules_root_dir = setenv.get_config(exeName=exeName, keepEnvironment=keep_env) - runSalomeCommon.setVerbose(args["verbosity"]) + runSalomeCommon.setVerbose(args[verbosity_nam]) + kill_salome(args) # -- + + # Setup extension's env in salome on demand case + if args[on_demand_nam]: + runSalomeOnDemand.set_ext_env() + setenv.set_env(args, modules_list, modules_root_dir, keepEnvironment=keep_env) ior_fakens_filename = useSalome(args, modules_list, modules_root_dir) # Management of -t @@ -200,7 +208,7 @@ def main(exeName=None): proc = subprocess.Popen(command, shell=True, env = env) addToKillList(proc.pid, command) res = proc.wait() - if res: sys.exit(1) + if res: sys.exit(1) return args, ior_fakens_filename # ----------------------------------------------------------------------------- diff --git a/bin/runSalomeCommon.py b/bin/runSalomeCommon.py index 7ff22727d..63b3c8d8d 100755 --- a/bin/runSalomeCommon.py +++ b/bin/runSalomeCommon.py @@ -34,6 +34,11 @@ import subprocess from salomeContextUtils import ScriptAndArgsObjectEncoder import platform import logging + +# Setting formatter in setVerbose() was commented because adding of handler +# breaks using of root logger in other modules and cause many double lines in logs. +FORMAT = '%(levelname)s : %(asctime)s : [%(filename)s:%(funcName)s:%(lineno)s] : %(message)s' +logging.basicConfig(format=FORMAT, force=True) logger = logging.getLogger() class ColoredFormatter(logging.Formatter): @@ -66,20 +71,20 @@ class BackTraceFormatter(logging.Formatter): return logging.Formatter.format(self, record) def setVerbose(verbose): - from packaging import version - current_version = version.parse("{}.{}".format(sys.version_info.major,sys.version_info.minor)) - version_ref = version.parse("3.5.0") - global logger - formatter = None - if current_version >= version_ref: - formatter = BackTraceFormatter('%(levelname)s : %(asctime)s : %(message)s ',style='%') - else: - formatter = logging.Formatter('%(levelname)s : %(asctime)s : %(message)s ',style='%') - formatter.default_time_format = '%H:%M:%S' - formatter.default_msec_format = "%s.%03d" - stream_handler = logging.StreamHandler() - stream_handler.setFormatter(formatter) - logger.addHandler(stream_handler) + # from packaging import version + # current_version = version.parse("{}.{}".format(sys.version_info.major,sys.version_info.minor)) + # version_ref = version.parse("3.5.0") + # global logger + # formatter = None + # if current_version >= version_ref: + # formatter = BackTraceFormatter('%(levelname)s : %(asctime)s : %(message)s ',style='%') + # else: + # formatter = logging.Formatter('%(levelname)s : %(asctime)s : %(message)s ',style='%') + # formatter.default_time_format = '%H:%M:%S' + # formatter.default_msec_format = "%s.%03d" + # stream_handler = logging.StreamHandler() + # stream_handler.setFormatter(formatter) + # logger.addHandler(stream_handler) verbose_map = { "0": logging.WARNING, "1": logging.INFO, "2": logging.DEBUG} if verbose in verbose_map: @@ -356,7 +361,7 @@ class CommonSessionServer(Server): @abc.abstractmethod def getSessionServerExe(self): pass - + def setpath(self,modules_list,modules_root_dir): list_modules = modules_list[:] list_modules.reverse() @@ -407,7 +412,7 @@ class SessionServer(CommonSessionServer): super().__init__(args,modules_list,modules_root_dir) import KernelBasis KernelBasis.setSSLMode(False) - + def getSessionServerExe(self): return "SALOME_Session_Server" # --- diff --git a/bin/runSalomeOnDemand.py b/bin/runSalomeOnDemand.py index 3a0272ee9..47351851b 100755 --- a/bin/runSalomeOnDemand.py +++ b/bin/runSalomeOnDemand.py @@ -33,7 +33,6 @@ 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, \ @@ -73,7 +72,7 @@ def module_from_filename(filename): return module -def set_ext_env(app_name, version): +def set_ext_env(app_name='', version=''): """ Set an environment to start SALOME as a set of extensions. @@ -88,7 +87,7 @@ def set_ext_env(app_name, version): logger.debug('Set an env for app: %s, version: %s...', app_name, version) # Get the root directory - levels_up = 2 + levels_up = 4 app_root = str(Path(__file__).resolve().parents[levels_up - 1]) logger.debug('App root: %s', app_root) @@ -123,10 +122,8 @@ def set_ext_env(app_name, version): if __name__ == "__main__": if len(sys.argv) == 3: - arg_1, arg_2 = sys.argv[1:] # pylint: disable=unbalanced-tuple-unpacking + arg_1, arg_2 = sys.argv[1:] set_ext_env(arg_1, arg_2) - - runSalome.runSalome() else: logger.error('You must provide all the arguments!') logger.info(set_ext_env.__doc__)