106 lines
2.5 KiB
C++
Raw Normal View History

2020-10-29 21:16:45 +03:00
#include "deb.h"
#include <deployconfig.h>
#include <pathutils.h>
#include <packagecontrol.h>
#include <QProcess>
2020-10-29 21:16:45 +03:00
Deb::Deb(FileManager *fileManager):
iDistribution(fileManager)
{
setLocation("tmp DEB");
2020-10-29 21:16:45 +03:00
}
bool Deb::deployTemplate(PackageControl &pkg) {
// default template
const DeployConfig *cfg = DeployCore::_config;
for (auto it = cfg->packages().begin();
it != cfg->packages().end(); ++it) {
auto package = it.value();
TemplateInfo info;
2020-11-10 14:07:54 +03:00
bool fDefaultPakcage;
if (!collectInfo(it, cfg, info, fDefaultPakcage)) {
return false;
2020-11-09 16:33:50 +03:00
}
2020-10-29 21:16:45 +03:00
auto local = location(info.Name);
2020-11-09 16:33:50 +03:00
auto localData = dataLocation(info.Name);
2020-10-29 21:16:45 +03:00
2020-11-09 16:33:50 +03:00
if (!pkg.movePackage(it.key(), localData)) {
2020-10-29 21:16:45 +03:00
return false;
}
2020-11-09 16:33:50 +03:00
QHash<QString, QString> replace = {
{"default", info.Name}
};
if (!unpackDir(":/Templates/DEB/Distributions/Templates/deb",
local, info, {""}, replace)) {
return false;
}
2020-11-09 16:33:50 +03:00
outFiles.push_back(info.Name + ".deb");
packageFolders.push_back(local);
2020-10-29 21:16:45 +03:00
}
return true;
}
bool Deb::removeTemplate() const {
2020-11-09 16:33:50 +03:00
const DeployConfig *cfg = DeployCore::_config;
2020-10-29 21:16:45 +03:00
2020-11-09 16:33:50 +03:00
registerOutFiles();
return QDir(cfg->getTargetDir() + "/" + getLocation()).removeRecursively();
2020-10-29 21:16:45 +03:00
}
Envirement Deb::toolKitEnv() const {
Envirement result;
result.addEnv(QProcessEnvironment::systemEnvironment().value("PATH"));
2020-10-29 21:16:45 +03:00
return result;
2020-10-29 21:16:45 +03:00
}
QProcessEnvironment Deb::processEnvirement() const {
return QProcessEnvironment::systemEnvironment();
2020-10-29 21:16:45 +03:00
}
QList<SystemCommandData> Deb::runCmd() {
QList<SystemCommandData> res;
for (const auto& dir: packageFolders) {
res.push_back({"dpkg-deb", QStringList{"--build", "--verbose"} << dir});
}
2020-10-29 21:16:45 +03:00
return res;
2020-10-29 21:16:45 +03:00
}
QStringList Deb::outPutFiles() const {
2020-11-09 16:33:50 +03:00
return outFiles;
}
2020-10-29 21:16:45 +03:00
2020-11-09 16:33:50 +03:00
bool Deb::cb() const {
const DeployConfig* cfg = DeployCore::_config;
QString from = cfg->getTargetDir() + "/" + getLocation() + "/";
QString to = cfg->getTargetDir() + "/" + getLocation() + "/../";
for (const QString& file : outPutFiles()) {
if(!moveData(from + file, to, "")) {
return false;
}
}
return true;
2020-10-29 21:16:45 +03:00
}
QString Deb::dataLocation(const QString &packageName) const {
2020-11-09 16:33:50 +03:00
return location(packageName) + "/opt/" + packageName;
}
QString Deb::location(const QString &packageName) const {
const DeployConfig* cfg = DeployCore::_config;
return cfg->getTargetDir() + "/" + getLocation() + "/" + packageName;
}