Salome HOME
Copyright update 2021
[tools/libbatch.git] / src / Local / Job_Local.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * Job_Local.cxx :
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Mail   : mailto:ivan.dutka-malen@der.edf.fr
27  * Date   : Fri Nov 14 11:00:39 2003
28  * Projet : Salome 2
29  *
30  */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #ifndef WIN32
35 #include <unistd.h>
36 #endif
37
38 #include "Constants.hxx"
39 #include "Job_Local.hxx"
40
41 using namespace std;
42
43 namespace Batch {
44
45   // Constructeur
46   Job_Local::Job_Local(const Job & job) :
47     _command(), _param(job.getParametre()), _env(job.getEnvironnement())
48   {
49     // On convertit les objets Parametre et Environnement en liste chainee d'attributs + operateur
50     addEnvironnement( _env   );
51     addParametre    ( _param );
52   }
53
54
55   // Destructeur
56   Job_Local::~Job_Local()
57   {
58   }
59
60
61   void Job_Local::addParametre(const Parametre & P)
62   {
63     // En dernier, on ajoute le chemin complet de la commande
64     _command += P[EXECUTABLE].str();
65   }
66
67
68   void Job_Local::addEnvironnement(const Environnement & E)
69   {
70     for(Environnement::const_iterator it=E.begin(); it != E.end(); it++) {
71       string variable = (*it).first;
72       string value    = (*it).second;
73
74       // On remplace toutes les occurences de single-quote par backslash-single-quote
75       for(size_t pos=0; pos < value.size(); pos++) {
76         pos = value.find("'", pos);
77         if ( pos > value.size() ) break;
78         value.replace(pos, 1, "\'");
79       }
80       _command += variable + "='" + value + "' ";
81     }
82   }
83
84   string Job_Local::getCommand(void) const {
85     return _command;
86   }
87
88
89   // Retourne l'objet Parametre
90   Parametre Job_Local::getParametre() const
91   {
92     return _param;
93   }
94
95   // Retourne l'objet Environnement
96   Environnement Job_Local::getEnvironnement() const
97   {
98     return _env;
99   }
100
101
102 }