1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * BatchManager_Local_RSH.cxx :
25 * Auteur : Ivan DUTKA-MALEN - EDF R&D
26 * Mail : mailto:ivan.dutka-malen@der.edf.fr
27 * Date : Thu Nov 6 10:17:22 2003
33 # include <SALOMEconfig.h>
40 #include <sys/types.h>
50 #include "Batch_IOMutex.hxx"
51 #include "Batch_BatchManager_Local_RSH.hxx"
53 #include "Batch_config.h"
56 #error "RCP undefined. You must set RCP to a valid path to a rcp-like command."
60 #error "RSH undefined. You must set RSH to a valid path to a rsh-like command."
69 BatchManager_Local_RSH::BatchManager_Local_RSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
74 BatchManager_Local_RSH::~BatchManager_Local_RSH()
79 // Methode abstraite qui renvoie la commande de copie du fichier source en destination
80 string BatchManager_Local_RSH::copy_command(const std::string & user_source,
81 const std::string & host_source,
82 const std::string & source,
83 const std::string & user_destination,
84 const std::string & host_destination,
85 const std::string & destination) const
87 ostringstream fullsource;
88 if (host_source.size() != 0) {
89 if (user_source.size() != 0) {
91 fullsource << host_source << "." << user_source << ":";
93 fullsource << user_source << "@" << host_source << ":";
96 fullsource << host_source << ":";
101 ostringstream fulldestination;
102 if (host_destination.size() != 0) {
103 if (user_destination.size() != 0) {
105 fulldestination << host_destination << "." << user_destination << ":";
107 fulldestination << user_destination << "@" << host_destination << ":";
110 fulldestination << host_destination << ":";
113 fulldestination << destination;
115 ostringstream copy_cmd;
116 copy_cmd << "\"" << RCP << "\" " << fullsource.str() << " " << fulldestination.str();
117 return copy_cmd.str();
120 // Methode abstraite qui renvoie la commande a executer
121 string BatchManager_Local_RSH::exec_command(Parametre & param) const
123 ostringstream exec_sub_cmd;
124 exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE];
126 if (param.find(ARGUMENTS) != param.end()) {
127 Versatile V = param[ARGUMENTS];
128 for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
129 StringType argt = * static_cast<StringType *>(*it);
131 exec_sub_cmd << " " << arg;
136 Versatile new_arguments;
137 new_arguments.setMaxSize(0);
138 new_arguments = string(param[EXECUTIONHOST]);
141 if (param.find(USER) != param.end()) {
142 new_arguments += "-l";
143 new_arguments += string(param[USER]);
146 new_arguments += exec_sub_cmd.str();
148 param[ARGUMENTS] = new_arguments;
150 // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
151 param[EXECUTABLE] = RSH;
157 // Methode qui renvoie la commande d'effacement du fichier
158 string BatchManager_Local_RSH::remove_command(const std::string & user_destination,
159 const std::string & host_destination,
160 const std::string & destination) const
162 string fulldestination = (host_destination.size()) ? host_destination : "localhost";
163 if (user_destination.size() != 0) {
164 fulldestination += " -l " + user_destination;
167 // We consider here that the remote system is UNIX-like and has a "rm" command. Using the
168 // RM macro would be pointless here since the remote system is different from the local one.
169 ostringstream remove_cmd;
170 remove_cmd << "\"" << RSH << "\" " << fulldestination;
174 remove_cmd << " rm " << destination;
175 return remove_cmd.str();