void set_number_of_retry(in long nbRetry);
+ void set_current_directory(in string cwd);
+
void set_startup_code(in string codeAtStartUp);
string get_startup_code();
#include "KernelBasis.hxx"
+#include <memory>
#include <sstream>
#include <stdexcept>
static int SALOME_NB_RETRY = DFT_SALOME_NB_RETRY;
+static bool SALOME_FW_CWD_STATUS = false;
+
SALOME::BigObjTransferProtocol SALOME::FromIntToBigObjOnDiskProtocol(char protocol)
{
switch( protocol )
DefaultPyExecMode = isEnvVarSet();
return DefaultPyExecMode;
}
+
+bool SALOME::GetForwardCurrentDirectoryStatus()
+{
+ return SALOME_FW_CWD_STATUS;
+}
+
+void SALOME::SetForwardCurrentDirectoryStatus(bool newStatus)
+{
+ SALOME_FW_CWD_STATUS = newStatus;
+}
+
+extern "C"
+{
+#ifndef WIN32
+# include <unistd.h>
+#else
+# include <windows.h>
+#endif
+}
+
+#ifdef WIN32
+#define getcwd _getcwd
+#endif
+
+auto CStyleDeleter = [](char *ptr) { if(ptr) free(ptr); };
+using AutoCDeleter = std::unique_ptr<char, decltype(CStyleDeleter)>;
+
+std::string SALOME::GetCurrentWorkingDirectory()
+{
+ AutoCDeleter cwdPtr( getcwd( nullptr,10000 ), CStyleDeleter );
+ return std::string( cwdPtr.get() );
+}
bool BASICS_EXPORT BigObjOnDiskDirectoryDefined();
void BASICS_EXPORT SetNumberOfRetry(int nbRetry);
int BASICS_EXPORT GetNumberOfRetry();
+ bool BASICS_EXPORT GetForwardCurrentDirectoryStatus();
+ void BASICS_EXPORT SetForwardCurrentDirectoryStatus(bool newStatus);
+ std::string BASICS_EXPORT GetCurrentWorkingDirectory();
}
%rename (SetDirectoryForReplayFiles) SetDirectoryForReplayFilesSwig;
%rename (SetNumberOfRetry) SetNumberOfRetrySwig;
%rename (GetNumberOfRetry) GetNumberOfRetrySwig;
+%rename (GetForwardCurrentDirectoryStatus) GetForwardCurrentDirectoryStatusSwig;
+%rename (SetForwardCurrentDirectoryStatus) SetForwardCurrentDirectoryStatusSwig;
bool getSSLMode();
void setSSLMode(bool sslMode);
return SALOME::GetNumberOfRetry( );
}
+bool GetForwardCurrentDirectoryStatusSwig()
+{
+ return SALOME::GetForwardCurrentDirectoryStatus();
+}
+
+void SetForwardCurrentDirectoryStatusSwig(bool newStatus)
+{
+ SALOME::SetForwardCurrentDirectoryStatus(newStatus);
+}
+
std::string GetDirectoryForReplayFilesSwig()
{
return SALOME::GetDirectoryForReplayFiles();
SALOME::SetNumberOfRetry( nbRetry );
}
+void Abstract_Engines_Container_i::set_current_directory(const char *cwd)
+{
+ AutoGIL gstate;
+ AutoPyRef result = PyObject_CallMethod(_pyCont,(char*)"setCurrentDirectory","s",cwd,nullptr);
+ if (PyErr_Occurred())
+ {
+ std::string error("can not set logfilename");
+ PyErr_Print();
+ THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR);
+ }
+}
+
void Abstract_Engines_Container_i::set_directory_for_replay_files(const char *directory)
{
SALOME::SetDirectoryForReplayFiles( directory );
import salome_utils
salome_utils.positionVerbosityOfLoggerRegardingState()
logging.debug("positionVerbosityOfLogger PID = {}".format(os.getpid()))
+
+ def setCurrentDirectory(self, newCwd):
+ os.chdir( newCwd )
def monitoringtimeresms(self):
return self._timeIntervalInMs
}
}
cont->override_environment_python( envCorba );
+ if( SALOME::GetForwardCurrentDirectoryStatus() )
+ cont->set_current_directory( SALOME::GetCurrentWorkingDirectory().c_str() );
if( !_code_to_exe_on_startup.empty() )
{
INFOS("[GiveContainer] container " << containerNameInNS << " python code executed " << _code_to_exe_on_startup);
void set_number_of_retry(CORBA::Long nbRetry) override;
+ void set_current_directory(const char *cwd) override;
+
void set_directory_for_replay_files(const char *directory) override;
void set_startup_code(const char *codeAtStartUp) override;
import pickle
import tempfile
import pylauncher
+import KernelBasis
class TestProxy(unittest.TestCase):
def testProxy(self):
self.assertTrue(f.read()=="coucou")
os.unlink( tmpFileName.name ) # context manager do not clean file
+ def testWorkingDirectoryForward(self):
+ """
+ [EDF30062] test of forward of current directory overriding entry in Catalog
+ """
+ KernelBasis.SetForwardCurrentDirectoryStatus( True ) # key point
+ hostname = "localhost"
+ cp = pylauncher.GetRequestForGiveContainer(hostname,"container_test")
+
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ os.chdir( str( tmpdirname ) )
+ cp = pylauncher.GetRequestForGiveContainer("localhost","gg")
+ cont = salome.cm.GiveContainer(cp)
+
+ pyscript2 = cont.createPyScriptNode("testScript","""import os
+ret = os.getcwd()
+""")
+ #
+ import SALOME_PyNode
+ poa = salome.orb.resolve_initial_references("RootPOA")
+ obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( ([],{}) ))
+ id_o = poa.activate_object(obj)
+ refPtr = poa.id_to_reference(id_o)
+ #
+ pyscript2.executeFirst(refPtr)
+ ret2 = pyscript2.executeSecond(["ret"])
+ #
+ ret2 = ret2[0]
+ ret3 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret2).data() )
+ self.assertEqual(ret3,str(tmpdirname)) # key point
+ #
+ cont.Shutdown()
+ ################
+ KernelBasis.SetForwardCurrentDirectoryStatus( False ) # key point
+ cp = pylauncher.GetRequestForGiveContainer(hostname,"container_test")
+
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ os.chdir( str( tmpdirname ) )
+ cp = pylauncher.GetRequestForGiveContainer("localhost","gg")
+ cont = salome.cm.GiveContainer(cp)
+
+ pyscript2 = cont.createPyScriptNode("testScript","""import os
+ret = os.getcwd()
+""")
+ #
+ import SALOME_PyNode
+ poa = salome.orb.resolve_initial_references("RootPOA")
+ obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( ([],{}) ))
+ id_o = poa.activate_object(obj)
+ refPtr = poa.id_to_reference(id_o)
+ #
+ pyscript2.executeFirst(refPtr)
+ ret2 = pyscript2.executeSecond(["ret"])
+ #
+ ret2 = ret2[0]
+ ret3 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret2).data() )
+ self.assertNotEqual(ret3,str(tmpdirname)) # key point
+ #
+ cont.Shutdown()
+
if __name__ == '__main__':
salome.standalone()
salome.salome_init()