/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program 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 3 of the License, or (at your option)
any later version.

    This program 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 LICENSE and COPYING files for more details.
*/

#include "tprocessor.h"
#include <iostream>
#include <stdlib.h>

namespace tuplesd{

std::string ProcessorError::info() const
{
	return what();
}

TuplesPorcessor::TuplesPorcessor(const std::string &tuplesproc_path)
	: tuplesproc_path_(tuplesproc_path)
{
	// noop?
}
bool TuplesPorcessor::ProcessTuples(const std::string &indir, const std::string &outdir,
		const std::string &matrix_name, bool loud)
{
	std::stringstream cmd;

	cmd << "cd \"" << indir << "\" && 7z x tuples.7z && rm tuples.7z";

	if(loud)
		std::cout << "Will unpack tuples..." << std::endl;

	system(cmd.str().c_str()); // TODO evil, change to libs cals

	std::stringstream cmd2;


	cmd2 << tuplesproc_path_ << " --input " << indir  << " --out " << outdir
		<< " --matrix-name " << matrix_name;

	bool suc = system(cmd2.str().c_str()) == 0; // TODO evil, change tuplesproc to library

	std::stringstream cmd3;
	cmd3 << "rm -rf " << indir; // TODO more evil stuff

	system(cmd3.str().c_str()); // TODO evil^2, change to libs cals

	return suc;

}


} // ns tuplesd
