2020-01-04 16:39:25 +03:00
|
|
|
#include "Distributions/idistribution.h"
|
2020-01-16 15:25:36 +03:00
|
|
|
#include "deployconfig.h"
|
2020-01-04 16:39:25 +03:00
|
|
|
#include "packing.h"
|
2020-01-05 13:58:38 +03:00
|
|
|
#include "quasarapp.h"
|
|
|
|
#include <QDebug>
|
2020-01-12 19:48:22 +03:00
|
|
|
#include <QProcess>
|
2020-01-05 13:58:38 +03:00
|
|
|
#include <QThread>
|
2020-01-04 16:39:25 +03:00
|
|
|
|
|
|
|
Packing::Packing() {
|
2020-01-20 11:23:29 +03:00
|
|
|
_proc = new QProcess(this);
|
2020-01-04 16:39:25 +03:00
|
|
|
|
2020-01-20 15:43:00 +03:00
|
|
|
connect(_proc, SIGNAL(readyReadStandardError()),
|
|
|
|
this, SLOT(handleOutputUpdate()));
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-01-20 15:43:00 +03:00
|
|
|
connect(_proc, SIGNAL(readyReadStandardOutput()),
|
|
|
|
this, SLOT(handleOutputUpdate()));
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-01-04 16:39:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Packing::~Packing() {
|
2020-01-05 13:58:38 +03:00
|
|
|
_proc->kill();
|
2020-01-04 16:39:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Packing::setDistribution(iDistribution *pakage) {
|
|
|
|
_pakage = pakage;
|
|
|
|
}
|
|
|
|
|
2020-01-20 16:40:18 +03:00
|
|
|
bool Packing::create() {
|
2020-01-04 16:39:25 +03:00
|
|
|
|
|
|
|
if (!_pakage)
|
|
|
|
return false;
|
|
|
|
|
2020-01-14 15:48:35 +03:00
|
|
|
if (!_pakage->deployTemplate())
|
|
|
|
return false;
|
|
|
|
|
2020-01-05 13:58:38 +03:00
|
|
|
if (!_pakage->runCmd().size())
|
|
|
|
return true;
|
|
|
|
|
2020-01-16 15:25:36 +03:00
|
|
|
const DeployConfig *cfg = DeployCore::_config;
|
|
|
|
|
2020-05-04 20:24:21 +03:00
|
|
|
QFileInfo cmdInfo(_pakage->runCmd());
|
|
|
|
|
|
|
|
auto allExecRight = QFile::ExeUser | QFile::ExeGroup | QFile::ExeOwner;
|
|
|
|
if (!cmdInfo.permission(allExecRight)) {
|
|
|
|
QFile::setPermissions(cmdInfo.absoluteFilePath(), cmdInfo.permissions() | allExecRight);
|
|
|
|
}
|
|
|
|
|
2020-01-05 13:58:38 +03:00
|
|
|
_proc->setProgram(_pakage->runCmd());
|
2020-01-16 11:10:16 +03:00
|
|
|
_proc->setProcessEnvironment(_proc->processEnvironment());
|
2020-01-05 13:58:38 +03:00
|
|
|
_proc->setArguments(_pakage->runArg());
|
2020-01-16 15:25:36 +03:00
|
|
|
_proc->setWorkingDirectory(cfg->getTargetDir());
|
2020-01-05 13:58:38 +03:00
|
|
|
|
|
|
|
_proc->start();
|
|
|
|
|
2020-01-15 18:31:09 +03:00
|
|
|
if (!_proc->waitForStarted(1000)) {
|
2020-01-05 13:58:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-20 16:40:18 +03:00
|
|
|
if (!_proc->waitForFinished(-1)) {
|
2020-01-05 13:58:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-16 15:25:36 +03:00
|
|
|
auto exit = QString("exit code = %0").arg(_proc->exitCode());
|
|
|
|
QString stdoutLog = _proc->readAllStandardOutput();
|
|
|
|
QString erroutLog = _proc->readAllStandardError();
|
|
|
|
auto message = QString("message = %0").arg(stdoutLog + " " + erroutLog);
|
|
|
|
|
2020-04-14 17:59:12 +03:00
|
|
|
if (_proc->exitCode() != 0) {
|
|
|
|
QuasarAppUtils::Params::log(message, QuasarAppUtils::Error);
|
|
|
|
|
|
|
|
if (QuasarAppUtils::Params::isDebug())
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-16 15:25:36 +03:00
|
|
|
|
2020-01-20 16:40:18 +03:00
|
|
|
_pakage->removeTemplate();
|
2020-01-15 11:50:30 +03:00
|
|
|
|
2020-04-14 17:59:12 +03:00
|
|
|
return !_proc->exitCode();
|
2020-01-04 16:39:25 +03:00
|
|
|
}
|
2020-01-05 13:58:38 +03:00
|
|
|
|
|
|
|
void Packing::handleOutputUpdate() {
|
2020-01-20 15:43:00 +03:00
|
|
|
|
2020-01-12 20:13:40 +03:00
|
|
|
QByteArray stdoutLog = _proc->readAllStandardOutput();
|
|
|
|
QByteArray erroutLog = _proc->readAllStandardError();
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-01-12 20:13:40 +03:00
|
|
|
if (stdoutLog.size())
|
2020-04-04 15:43:46 +03:00
|
|
|
QuasarAppUtils::Params::log(stdoutLog,
|
|
|
|
QuasarAppUtils::Info);
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-01-12 20:13:40 +03:00
|
|
|
if (erroutLog.size())
|
2020-04-04 15:43:46 +03:00
|
|
|
QuasarAppUtils::Params::log(erroutLog,
|
|
|
|
QuasarAppUtils::Info);
|
2020-01-05 13:58:38 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 13:24:01 +03:00
|
|
|
|