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).
*/
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);
{
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
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<Engines::FieldsDict> ret( new Engines::FieldsDict );
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
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;
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: