Salome HOME
Merge from BR_LIBBATCH_2_0
[tools/libbatch.git] / src / Local / Job_Local.cxx
diff --git a/src/Local/Job_Local.cxx b/src/Local/Job_Local.cxx
new file mode 100644 (file)
index 0000000..f7109a7
--- /dev/null
@@ -0,0 +1,102 @@
+//  Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Job_Local.cxx :
+ *
+ * Auteur : Ivan DUTKA-MALEN - EDF R&D
+ * Mail   : mailto:ivan.dutka-malen@der.edf.fr
+ * Date   : Fri Nov 14 11:00:39 2003
+ * Projet : Salome 2
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
+#include "Constants.hxx"
+#include "Job_Local.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+  // Constructeur
+  Job_Local::Job_Local(const Job & job) :
+    _command(), _param(job.getParametre()), _env(job.getEnvironnement())
+  {
+    // On convertit les objets Parametre et Environnement en liste chainee d'attributs + operateur
+    addEnvironnement( _env   );
+    addParametre    ( _param );
+  }
+
+
+  // Destructeur
+  Job_Local::~Job_Local()
+  {
+  }
+
+
+  void Job_Local::addParametre(const Parametre & P)
+  {
+    // En dernier, on ajoute le chemin complet de la commande
+    _command += P[EXECUTABLE].str();
+  }
+
+
+  void Job_Local::addEnvironnement(const Environnement & E)
+  {
+    for(Environnement::const_iterator it=E.begin(); it != E.end(); it++) {
+      string variable = (*it).first;
+      string value    = (*it).second;
+
+      // On remplace toutes les occurences de single-quote par backslash-single-quote
+      for(size_t pos=0; pos < value.size(); pos++) {
+        pos = value.find("'", pos);
+        if ( pos > value.size() ) break;
+        value.replace(pos, 1, "\'");
+      }
+      _command += variable + "='" + value + "' ";
+    }
+  }
+
+  string Job_Local::getCommand(void) const {
+    return _command;
+  }
+
+
+  // Retourne l'objet Parametre
+  Parametre Job_Local::getParametre() const
+  {
+    return _param;
+  }
+
+  // Retourne l'objet Environnement
+  Environnement Job_Local::getEnvironnement() const
+  {
+    return _env;
+  }
+
+
+}