testing...
This commit is contained in:
@@ -65,7 +65,6 @@ int main(int argc, char **argv) {
|
|||||||
setDebugLevel(LOG_NOTICE);
|
setDebugLevel(LOG_NOTICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//return 0;
|
//return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -172,7 +171,7 @@ int main(int argc, char **argv) {
|
|||||||
qInfo() << "using customer repository" << psaRepoDir;
|
qInfo() << "using customer repository" << psaRepoDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<QString> c = internal::dcCandidateToInstall();
|
std::unique_ptr<QString> c = internal::dcCandidateToInstall("/etc/dc/");
|
||||||
if (c) {
|
if (c) {
|
||||||
fi.setFile(*c);
|
fi.setFile(*c);
|
||||||
if (fi.exists() == false) {
|
if (fi.exists() == false) {
|
||||||
|
|||||||
@@ -392,6 +392,10 @@ int Update::run() {
|
|||||||
|
|
||||||
qInfo() << "DC auto request OFF";
|
qInfo() << "DC auto request OFF";
|
||||||
|
|
||||||
|
// dennis einzelne linie
|
||||||
|
qCritical() << "start dc-update for" << m_dcFileName << "at" << m_start.toString(Qt::ISODate);
|
||||||
|
|
||||||
|
|
||||||
QByteArray ba = loadBinaryDCFile(m_dcFileName);
|
QByteArray ba = loadBinaryDCFile(m_dcFileName);
|
||||||
if (ba.size() > 0) {
|
if (ba.size() > 0) {
|
||||||
m_totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
|
m_totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
|
||||||
|
|||||||
166
common/src/utils_internal.cpp
Normal file
166
common/src/utils_internal.cpp
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#include "utils_internal.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QFileInfoList>
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
int read1stLineOfFile(QString fileName) {
|
||||||
|
QFile f(fileName);
|
||||||
|
if (f.exists()) {
|
||||||
|
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QTextStream in(&f);
|
||||||
|
in.setCodec("UTF-8");
|
||||||
|
while(!in.atEnd()) {
|
||||||
|
return in.readLine().toInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString customerRepoRoot() {
|
||||||
|
return "/opt/app/tools/atbupdate/";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString customerRepoDirName() {
|
||||||
|
int const customerNr = read1stLineOfFile("/mnt/system_data/cust_nr");
|
||||||
|
return (customerNr != -1) ? QString("customer_%1").arg(customerNr) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString customerRepoDir() {
|
||||||
|
QString const &n = customerRepoDirName();
|
||||||
|
QString const &r = customerRepoRoot();
|
||||||
|
return !n.isEmpty() ? QDir::cleanPath(r + QDir::separator() + n) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString customerRepoDcDir() {
|
||||||
|
QString const &r = customerRepoDir();
|
||||||
|
return QDir::cleanPath(r + QDir::separator() + "etc/dc/");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool customerRepoExists() {
|
||||||
|
QString const repoDir{customerRepoDir()};
|
||||||
|
return !repoDir.isEmpty() ? QDir(repoDir).exists() : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString repositoryUrl() {
|
||||||
|
return "gitea@ptu-config.atb-comm.de:ATB/";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString branchName() {
|
||||||
|
int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
||||||
|
if (zoneNr != -1) {
|
||||||
|
return QString("zg1/zone%1").arg(zoneNr);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<QSettings> readSettings(QString const &optionalDirName) {
|
||||||
|
std::unique_ptr<QSettings> settings{std::make_unique<QSettings>()};
|
||||||
|
|
||||||
|
QString const fileName{settings->applicationName() + ".ini"};
|
||||||
|
QDir d;
|
||||||
|
|
||||||
|
if (!optionalDirName.isEmpty()) {
|
||||||
|
d = QDir{optionalDirName};
|
||||||
|
if (d.exists()) { // try to find ini-file under optionalDirname
|
||||||
|
QFileInfo fi{d, optionalDirName};
|
||||||
|
if (fi.exists()) {
|
||||||
|
settings.reset(new QSettings(fi.absoluteFilePath(), QSettings::IniFormat));
|
||||||
|
return settings;
|
||||||
|
} else {
|
||||||
|
qCritical() << fi.absoluteFilePath() << "not found."
|
||||||
|
<< "Try" << internal::DEFAULT_INI_DIR;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << optionalDirName << "not found."
|
||||||
|
<< "Try" << internal::DEFAULT_INSTALL_DIR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d = internal::DEFAULT_INI_DIR;
|
||||||
|
if (d.exists()) { // try to find ini-file under /etc/tools/atbupdate
|
||||||
|
QFileInfo fi{d, fileName};
|
||||||
|
if (fi.exists()) {
|
||||||
|
settings.reset(new QSettings(fi.absoluteFilePath(), QSettings::IniFormat));
|
||||||
|
return settings;
|
||||||
|
} else {
|
||||||
|
qCritical() << fi.absoluteFilePath() << "not found."
|
||||||
|
<< "Try" << internal::DEFAULT_INSTALL_DIR;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << internal::DEFAULT_INI_DIR << "not found."
|
||||||
|
<< "Try" << internal::DEFAULT_INSTALL_DIR;
|
||||||
|
}
|
||||||
|
d = QDir{internal::DEFAULT_INSTALL_DIR};
|
||||||
|
if (d.exists()) { // try to find ini-file under /opt/app/tools/atbupdate
|
||||||
|
QFileInfo fi{d, fileName};
|
||||||
|
if (fi.exists()) {
|
||||||
|
settings.reset(new QSettings(fi.absoluteFilePath(), QSettings::IniFormat));
|
||||||
|
return settings;
|
||||||
|
} else {
|
||||||
|
qCritical() << fi.absoluteFilePath() << "not found.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << internal::DEFAULT_INSTALL_DIR << "not found.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<QString> dcCandidateToInstall(QString const &dcDirectory) {
|
||||||
|
std::unique_ptr<QString> dcCandidate{nullptr};
|
||||||
|
|
||||||
|
qCritical() << __func__ << __LINE__ << dcDirectory;
|
||||||
|
|
||||||
|
QDir dcDir{dcDirectory.isEmpty() ? customerRepoDcDir() : dcDirectory};
|
||||||
|
if (dcDir.exists()) {
|
||||||
|
|
||||||
|
QFileInfoList fileInfoList =
|
||||||
|
dcDir.entryInfoList(QStringList("*.bin"),
|
||||||
|
QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||||
|
|
||||||
|
QFileInfo dc2cbin{dcDir.absoluteFilePath("dc2c.bin")};
|
||||||
|
|
||||||
|
|
||||||
|
if (dc2cbin.exists()) {
|
||||||
|
|
||||||
|
QCryptographicHash md5gen(QCryptographicHash::Md5);
|
||||||
|
QByteArray ba_dc2cbin{};
|
||||||
|
{
|
||||||
|
QFile f{dc2cbin.absoluteFilePath()};
|
||||||
|
if (f.open(QIODevice::ReadOnly)) {
|
||||||
|
md5gen.addData(f.readAll());
|
||||||
|
ba_dc2cbin = md5gen.result();
|
||||||
|
md5gen.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ba_dc2cbin.size() > 0) {
|
||||||
|
QFileInfoList::const_iterator it;
|
||||||
|
for (it = fileInfoList.cbegin(); it != fileInfoList.cend(); ++it) {
|
||||||
|
if (it->absoluteFilePath() != dc2cbin.absoluteFilePath()) {
|
||||||
|
QFile f{it->absoluteFilePath()};
|
||||||
|
if (f.open(QIODevice::ReadOnly)) {
|
||||||
|
md5gen.addData(f.readAll());
|
||||||
|
if (ba_dc2cbin == md5gen.result()) {
|
||||||
|
dcCandidate.reset(new QString(f.fileName()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
md5gen.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dcCandidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
Reference in New Issue
Block a user