From: Anthony Geay Date: Mon, 21 Aug 2023 06:22:08 +0000 (+0200) Subject: [EDF27816] : WIP X-Git-Tag: emc2p_1.4.0-rc1~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0bc1f6324216137ecd9806caa2f45d0715954cd2;p=modules%2Fkernel.git [EDF27816] : WIP --- diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 37c8d809a..11a21e1cc 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -80,6 +80,8 @@ module Engines void override_environment( in FieldsDict env ); + void override_environment_python( in FieldsDict env ); + FieldsDict get_os_environment(); /*! \brief Loads a new component class (dynamic library). diff --git a/idl/SALOME_PyNode.idl b/idl/SALOME_PyNode.idl index c3cf29276..30d2f7830 100644 --- a/idl/SALOME_PyNode.idl +++ b/idl/SALOME_PyNode.idl @@ -90,6 +90,8 @@ module Engines */ pickledArgs execute(in listofstring outargsname, in pickledArgs inargs) raises (SALOME::SALOME_Exception); + void executeSimple(in listofstring key, in listofstring val) raises (SALOME::SALOME_Exception); + /*! \brief first part of whole execute method. This split is to reduce the memory peak. */ void executeFirst(in SALOME::SenderByte inargs) raises (SALOME::SALOME_Exception); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index de015e08f..92209ebb6 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -1017,7 +1017,7 @@ void EffectiveOverrideEnvironment( const Engines::FieldsDict& env ) { if (env[i].value.type()->kind() == CORBA::tk_string) { - const char* value; + const char *value = nullptr; env[i].value >>= value; MESSAGE( env[i].key << " = " << value); #ifndef WIN32 @@ -1053,6 +1053,28 @@ void Abstract_Engines_Container_i::override_environment( const Engines::FieldsDi EffectiveOverrideEnvironment(env); } +void Abstract_Engines_Container_i::override_environment_python( const Engines::FieldsDict& env ) +{ + constexpr char NODE_NAME[] = "ScriptNodeForEnv"; + constexpr char SCRIPT[] = R"foo( +import os +for k,v in env: + os.environ[k] = v +)foo"; + Engines::PyScriptNode_var scriptNode = this->createPyScriptNode(NODE_NAME,SCRIPT); + auto sz = env.length(); + Engines::listofstring keys( sz ), vals( sz ); + for( auto i = 0 ; i < sz ; ++i ) + { + keys[i] = CORBA::string_dup( env[i].key ); + const char *value = nullptr; + env[i].value >>= value; + vals[i] = CORBA::string_dup( value ); + } + scriptNode->executeSimple(keys,vals); + this->removePyScriptNode(NODE_NAME); +} + Engines::FieldsDict *Abstract_Engines_Container_i::get_os_environment() { std::unique_ptr ret( new Engines::FieldsDict ); diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index bad409f90..013d25d5c 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -473,7 +473,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con envCorba[i].value <<= CORBA::string_dup( _override_env[i].second.c_str() ); } } - cont->override_environment( envCorba ); + cont->override_environment_python( envCorba ); return cont._retn(); } else diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 96996e5f9..f68b9652c 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -72,6 +72,8 @@ public: virtual Engines::EngineComponent_ptr create_component_instance(const char *componentName); + void override_environment_python( const Engines::FieldsDict& env ) override; + void override_environment( const Engines::FieldsDict& env ) override; Engines::FieldsDict *get_os_environment() override; diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 06555527c..d98ae6cfa 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -416,6 +416,18 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic): except Exception: raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"","PyScriptNode.assignNewCompiledCode (%s) : code to be executed \"%s\"" %(self.nodeName,codeStr),0)) + def executeSimple(self, key, val): + """ + Same as execute method except that no pickelization mecanism is implied here. No output is expected + """ + try: + self.context.update({ "env" : [(k,v) for k,v in zip(key,val)]}) + exec(self.ccode,self.context) + except Exception: + exc_typ,exc_val,exc_fr=sys.exc_info() + l=traceback.format_exception(exc_typ,exc_val,exc_fr) + raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyScriptNode: %s" % (self.nodeName),0)) + def execute(self,outargsname,argsin): """Execute the script stored in attribute ccode with pickled args (argsin)""" try: