CQtDeployer/Deploy/packing.cpp

76 lines
1.5 KiB
C++
Raw Normal View History

2020-01-04 16:39:25 +03:00
#include "Distributions/idistribution.h"
#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() {
_proc = new QProcess();
2020-01-04 16:39:25 +03:00
connect(_proc, &QProcess::readyReadStandardError,
this, &Packing::handleOutputUpdate, Qt::QueuedConnection);
connect(_proc, &QProcess::readyReadStandardOutput,
this, &Packing::handleOutputUpdate, Qt::QueuedConnection);
moveToThread( new QThread(this));
2020-01-04 16:39:25 +03:00
}
Packing::~Packing() {
if (_pakage)
delete _pakage;
_proc->kill();
delete _proc;
2020-01-04 16:39:25 +03:00
}
void Packing::setDistribution(iDistribution *pakage) {
_pakage = pakage;
}
bool Packing::create() {
if (!_pakage)
return false;
2020-01-14 15:48:35 +03:00
if (!_pakage->deployTemplate())
return false;
if (!_pakage->runCmd().size())
return true;
_proc->setProgram(_pakage->runCmd());
2020-01-16 11:10:16 +03:00
_proc->setProcessEnvironment(_proc->processEnvironment());
_proc->setArguments(_pakage->runArg());
_proc->start();
2020-01-15 18:31:09 +03:00
if (!_proc->waitForStarted(1000)) {
return false;
}
if (!_proc->waitForFinished(60000 * 10)) {
return false;
}
2020-01-15 11:50:30 +03:00
if (!_pakage->removeTemplate()) {
return false;
}
2020-01-04 16:39:25 +03:00
return true;
}
void Packing::handleOutputUpdate() {
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;
}