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-08-14 17:47:34 +03:00
|
|
|
#include "pathutils.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
|
|
|
}
|
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
void Packing::setDistribution(const QList<iDistribution*> &pakages) {
|
|
|
|
_pakage = pakages;
|
2020-01-04 16:39:25 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 16:40:18 +03:00
|
|
|
bool Packing::create() {
|
2020-01-04 16:39:25 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
for (auto package : _pakage) {
|
2020-01-04 16:39:25 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
if (!package)
|
|
|
|
return false;
|
2020-01-14 15:48:35 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
if (!package->deployTemplate())
|
|
|
|
return false;
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
if (package->runCmd().size()) {
|
|
|
|
const DeployConfig *cfg = DeployCore::_config;
|
2020-01-16 15:25:36 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
QFileInfo cmdInfo(_pakage->runCmd());
|
2020-05-04 20:24:21 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
auto allExecRight = QFile::ExeUser | QFile::ExeGroup | QFile::ExeOwner;
|
|
|
|
if (!cmdInfo.permission(allExecRight)) {
|
|
|
|
QFile::setPermissions(cmdInfo.absoluteFilePath(), cmdInfo.permissions() | allExecRight);
|
|
|
|
}
|
|
|
|
|
|
|
|
_proc->setProgram(_pakage->runCmd());
|
|
|
|
_proc->setProcessEnvironment(_proc->processEnvironment());
|
|
|
|
_proc->setArguments(_pakage->runArg());
|
|
|
|
_proc->setWorkingDirectory(cfg->getTargetDir());
|
|
|
|
|
|
|
|
_proc->start();
|
2020-05-04 20:24:21 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
if (!_proc->waitForStarted(1000)) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
if (!_proc->waitForFinished(-1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (_proc->exitCode() != 0) {
|
|
|
|
QuasarAppUtils::Params::log(message, QuasarAppUtils::Error);
|
|
|
|
|
|
|
|
if (QuasarAppUtils::Params::isDebug())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_pakage->removeTemplate();
|
2020-01-05 13:58:38 +03:00
|
|
|
|
|
|
|
}
|
2020-08-14 17:47:34 +03:00
|
|
|
}
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
QMultiMap<int ,QPair<QString, const DistroModule*>>
|
|
|
|
sortPackages(const QHash<QString, DistroModule> &input) {
|
|
|
|
QMultiMap<int, QPair<QString, const DistroModule *>> result;
|
|
|
|
for (auto it = input.cbegin(); it != input.cend(); ++it ) {
|
|
|
|
result.insert(0xFFFF - it.key().size(), {it.key(), &it.value()});
|
2020-01-05 13:58:38 +03:00
|
|
|
}
|
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
return result;
|
|
|
|
}
|
2020-01-16 15:25:36 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
void Packing::collectPackages() {
|
|
|
|
const DeployConfig *cfg = DeployCore::_config;
|
2020-04-14 17:59:12 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
auto sortedMap = sortPackages(cfg->packages());
|
|
|
|
|
|
|
|
for (auto &it : sortedMap) {
|
|
|
|
auto package = it.second;
|
|
|
|
|
|
|
|
QString Name = PathUtils::stripPath(it.first);
|
|
|
|
|
|
|
|
if (Name.isEmpty()) {
|
|
|
|
QFileInfo targetInfo(*package->targets().begin());
|
|
|
|
Name = targetInfo.baseName();
|
|
|
|
}
|
2020-01-16 15:25:36 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
if (!package->name().isEmpty()) {
|
|
|
|
Name = package->name();
|
|
|
|
}
|
2020-01-15 11:50:30 +03:00
|
|
|
|
2020-08-14 17:47:34 +03:00
|
|
|
QString tmpPakcageLocation = "tmp_data";
|
|
|
|
auto location = cfg->getTargetDir() + "/" + tmpPakcageLocation + "/" +
|
|
|
|
((it.first.isEmpty())? "Application": Name);
|
|
|
|
|
|
|
|
|
|
|
|
_packages.insert(it.first, location);
|
|
|
|
|
|
|
|
if (!moveData(cfg->getTargetDir() + "/" + it.first, location, tmpPakcageLocation)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
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,
|
2020-08-14 17:47:34 +03:00
|
|
|
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,
|
2020-08-14 17:47:34 +03:00
|
|
|
QuasarAppUtils::Info);
|
2020-01-05 13:58:38 +03:00
|
|
|
}
|
|
|
|
|
2020-01-20 13:24:01 +03:00
|
|
|
|