54 #define OUTPUT_FILE GetPath("__stdouterr") 58 : Param(_Param), local(
true), debug_level(_Param->get_class_debug_level(
GET_CLASS(*this)))
72 const std::string& log_file,
bool permissive,
bool throw_message)
112 command +=
"ssh " + _host_ +
" '";
115 if(!setupscr.empty())
119 command += setupscr +
" >& /dev/null; ";
123 command +=
". " + setupscr +
" >& /dev/null; ";
127 command +=
"if test -f " + _tool_ +
" ; then ";
128 command +=
" true; ";
130 command +=
" if test `which " + _tool_ +
"`; then ";
131 command +=
" true; ";
133 command +=
" false; ";
145 "Problems in checking \"" + _tool_ +
"\" executable" +
146 (!_host_.empty() ?
" on host \"" + _host_ +
"\"" +
147 (!setupscr.empty() ?
" with this setup script \"" + setupscr +
"\"!" :
"") :
149 Param->getOption<std::string>(OPT_output_temporary_directory) +
"/check_command_output", permissive,
false);
154 const std::string& _remote_path_,
bool force_remote)
159 if(!force_remote and
check_command(_tool_, setupscr,
"",
true) != -1)
161 if(!setupscr.empty())
169 executable +=
". " + setupscr +
" >& /dev/null; ";
176 else if(!_host_.empty())
181 THROW_ERROR(
"Login problems on host \"" + _host_ +
"\" or executable not available!");
187 if(!setupscr.empty())
200 if(!_remote_path_.empty())
202 command =
"ssh " + _host_ +
" ";
203 command +=
"'mkdir -p " + _remote_path_ +
"' >& " + std::string(
OUTPUT_FILE);
204 execute_command(command,
"Remote path cannot be created on the host machine \"" +
host +
"\"!",
205 Param->getOption<std::string>(OPT_output_temporary_directory) +
"/configure_output");
212 if(!force_remote && output_file.is_open() && !output_file.eof())
219 THROW_ERROR(
"Command \"" + _tool_ +
"\" not found!");
226 THROW_ASSERT(!parameters.empty(),
"Executable has not been specified");
227 std::string
command = parameters[0];
228 for(
unsigned int i = 1; i < parameters.size(); i++)
230 command += (
" " + parameters[i]);
243 std::vector<std::string> effective_files;
244 effective_files.reserve(files.size());
245 for(
auto&
file : files)
249 return effective_files;
254 std::string effective_file, file_to_be_copied;
257 std::filesystem::path
file(file_name);
258 std::string FileName = file.filename().string();
261 effective_file = file_name;
265 effective_file = FileName;
267 if(!
local and !overwrite)
270 command +=
"'if test -f " +
remote_path +
"/" + FileName +
" ; then ";
271 command +=
" true; ";
273 command +=
" false; ";
276 command,
"Login problems on host \"" +
host +
"\"!",
277 Param->getOption<std::string>(OPT_output_temporary_directory) +
"/determine_paths_output",
true);
289 if(!std::filesystem::exists(file))
291 THROW_ERROR(
"File \"" + file.string() +
"\" does not exists");
293 file_to_be_copied = file_name;
296 file_name = file_to_be_copied;
297 return effective_file;
303 std::vector<std::string> move_to_host(1,
"scp");
304 for(
const auto& i : files)
306 std::filesystem::path
file(i);
307 if(!std::filesystem::exists(file))
309 THROW_ERROR(
"File \"" + file.string() +
"\" does not exists");
313 move_to_host.push_back(i);
316 if(!
local and !files.empty())
319 move_to_host.push_back(
">& " + std::string(
OUTPUT_FILE));
321 execute_command(command,
"Input files cannot be moved on the host machine",
322 Param->getOption<std::string>(OPT_output_temporary_directory) +
"/prepare_input_files_output");
328 const std::vector<std::string>& output_files,
const std::string& log_file,
bool permissive)
339 std::vector<std::string> command_line(1,
executable);
340 for(
const auto& parameter : parameters)
342 command_line.push_back(parameter);
347 const auto ret =
execute_command(command,
"Returned error code!", log_file, permissive);
358 std::vector<std::string> removing(1,
"rm -rf");
359 for(
const auto&
file : files)
361 if(std::filesystem::exists(
file) and std::find(input_files.begin(), input_files.end(),
file) == input_files.end())
363 removing.push_back(
file);
364 std::filesystem::remove(
file);
367 if(removing.size() == 1)
373 Param->getOption<std::string>(OPT_output_temporary_directory) +
"/remove_files_output");
378 std::vector<std::string> move_from_host(1,
"scp ");
379 for(
const auto& i : files)
383 std::filesystem::path
file(i);
384 if(!std::filesystem::exists(file))
386 THROW_ERROR(
"File \"" + file.string() +
"\" has not been correctly created");
396 move_from_host.emplace_back(
".");
397 move_from_host.push_back(
">& " + std::string(
OUTPUT_FILE));
399 auto output_level =
Param->getOption<
unsigned int>(OPT_output_level);
401 execute_command(command,
"Generated files cannot be moved from the host machine",
402 Param->getOption<std::string>(OPT_output_temporary_directory) +
"/check_output_files_output");
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
File containing functions and utilities to support the printing of debug messagges.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
#define THROW_WARNING(str_expr)
helper function used to throw a warning in a standard way: though it uses PRINT_DBG_MEX, the debug level used is such that the message is always printed
Auxiliary methods for manipulating string.
bool IsError(const int error_value)
Utility include.
bool starts_with(const std::string &str, const std::string &pattern)
utility function used to read files.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
int PandaSystem(const ParameterConstRef Param, const std::string &system_command, bool host_exec, const std::string &output, const unsigned int type, const bool background, const size_t timeout)
System call forcing execution with bash.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
this class is used to manage the command-line or XML options.
#define PRINT_OUT_MEX(profLevel, curprofLevel, mex)
void CopyStdout(const std::string &filename)
Copy a file to the standard output.
#define OUTPUT_LEVEL_VERBOSE
verbose debugging print is performed.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...