CQtDeployer/Deploy/packing.cpp

93 lines
2.2 KiB
C++
Raw Normal View History

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"
#include "quasarapp.h"
#include <QDebug>
2020-01-12 19:48:22 +03:00
#include <QProcess>
#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-20 15:43:00 +03:00
connect(_proc, SIGNAL(readyReadStandardOutput()),
this, SLOT(handleOutputUpdate()));
connect(_proc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
this, &Packing::handleFinished, Qt::QueuedConnection);
2020-01-20 15:43:00 +03:00
// moveToThread( new QThread(this));
2020-01-04 16:39:25 +03:00
}
Packing::~Packing() {
_proc->kill();
2020-01-04 16:39:25 +03:00
}
void Packing::setDistribution(iDistribution *pakage) {
_pakage = pakage;
}
bool Packing::create(bool async) {
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;
if (!_pakage->runCmd().size())
return true;
2020-01-16 15:25:36 +03:00
const DeployConfig *cfg = DeployCore::_config;
_proc->setProgram(_pakage->runCmd());
2020-01-16 11:10:16 +03:00
_proc->setProcessEnvironment(_proc->processEnvironment());
_proc->setArguments(_pakage->runArg());
2020-01-16 15:25:36 +03:00
_proc->setWorkingDirectory(cfg->getTargetDir());
_proc->start();
2020-01-15 18:31:09 +03:00
if (!_proc->waitForStarted(1000)) {
return false;
}
2020-01-20 15:43:00 +03:00
if (!async && !_proc->waitForFinished(-1)) {
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);
QuasarAppUtils::Params::verboseLog(message,
QuasarAppUtils::Info);
2020-01-20 15:43:00 +03:00
if (!async) {
handleFinished(_proc->exitCode(), {});
2020-01-15 11:50:30 +03:00
}
2020-01-04 16:39:25 +03:00
return true;
}
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-12 20:13:40 +03:00
if (stdoutLog.size())
qInfo() << stdoutLog;
2020-01-12 20:13:40 +03:00
if (erroutLog.size())
qInfo() << erroutLog;
}
void Packing::handleFinished(int exitCode, QProcess::ExitStatus ) {
2020-01-20 15:43:00 +03:00
_pakage->removeTemplate();
emit sigFinished(exitCode);
}