Salome HOME
Allow usage of BatchManager_eClient methods in Python
[tools/libbatch.git] / src / Core / Batch_BatchManager_eClient.cxx
index ec5b8d8c85dcb64a8053f88a381a11243ab4b314..a7546459df9dba7441ebe0c46df9f6289560389a 100644 (file)
@@ -81,12 +81,8 @@ namespace Batch {
     Parametre params = job.getParametre();
     Versatile V = params[INFILE];
     Versatile::iterator Vit;
-    _username = string(params[USER]);
 
-    string subCommand = string("mkdir -p ") + string(params[TMPDIR]) + string("/logs");
-    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
-    cerr << command.c_str() << endl;
-    status = system(command.c_str());
+    status = _protocol.makeDirectory(string(params[TMPDIR]) + "/logs", _hostname, _username);
     if(status) {
       std::ostringstream oss;
       oss << status;
@@ -112,9 +108,9 @@ namespace Batch {
 #ifdef WIN32
       // On Windows, we make the remote file executable afterward because
       // pscp does not preserve access permissions on files
-      subCommand = string("chmod u+x ") + string(params[TMPDIR]) + "/" +
-                   string(params[EXECUTABLE]);
-      command = _protocol.getExecCommand(subCommand, _hostname, _username);
+      string subCommand = string("chmod u+x ") + string(params[TMPDIR]) + "/" +
+                          string(params[EXECUTABLE]);
+      string command = _protocol.getExecCommand(subCommand, _hostname, _username);
       cerr << command.c_str() << endl;
       status = system(command.c_str());
       if(status) {
@@ -145,18 +141,28 @@ namespace Batch {
 
   }
 
-  void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException)
+  void BatchManager_eClient::importOutputFiles( const Job & job, const string directory )
   {
     Parametre params = job.getParametre();
     Versatile V = params[OUTFILE];
     Versatile::iterator Vit;
     _username = string(params[USER]);
 
+    // Create local result directory
+    int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
+    if (status) {
+      string mess("Directory creation failed. Status is :");
+      ostringstream status_str;
+      status_str << status;
+      mess += status_str.str();
+      cerr << mess << endl;
+    }
+
     for(Vit=V.begin(); Vit!=V.end(); Vit++) {
       CoupleType cpt  = *static_cast< CoupleType * >(*Vit);
       Couple outputFile = cpt;
-      int status = _protocol.copyFile(outputFile.getRemote(), _hostname, _username,
-                                      directory, "", "");
+      status = _protocol.copyFile(outputFile.getRemote(), _hostname, _username,
+                                  directory, "", "");
       if (status) {
         // Try to get what we can (logs files)
         // throw BatchException("Error of connection on remote host");
@@ -169,8 +175,8 @@ namespace Batch {
     }
 
     // Copy logs
-    int status = _protocol.copyFile(string(params[TMPDIR]) + string("/logs"), _hostname, _username,
-                                   directory, "", "");
+    status = _protocol.copyFile(string(params[TMPDIR]) + string("/logs"), _hostname, _username,
+                                directory, "", "");
     if (status) {
       std::string mess("Copy logs directory failed ! status is :");
       ostringstream status_str;
@@ -181,7 +187,7 @@ namespace Batch {
 
   }
 
-  MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) throw(EmulationException)
+  MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl)
   {
     if(mpiImpl == "lam")
       return new MpiImpl_LAM();
@@ -285,13 +291,13 @@ namespace Batch {
   const std::string & BatchManager_eClient::getTmpDir()
   {
     if (tmpDirName.empty()) {
-      char * baseDir = getenv("TEMP");
+      const char * baseDir = getenv("TEMP");
       if (baseDir == NULL) baseDir = getenv("TMP");
       if (baseDir == NULL) baseDir = getenv("TEMPDIR");
       if (baseDir == NULL) baseDir = getenv("TMPDIR");
       if (baseDir == NULL) baseDir = "/tmp";
 
-      char * userName = getenv("USER");
+      const char * userName = getenv("USER");
       if (userName == NULL) userName = getenv("USERNAME");
       if (userName == NULL) userName = "unknown";