save files with comment

This commit is contained in:
Gerhard Hoffmann 2025-01-09 15:22:10 +01:00
parent 7bfb7f5a3b
commit 8f822c5383
17 changed files with 441 additions and 54 deletions

View File

@ -1,3 +1,3 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = DownloadDCFirmware DownloadDCJsonFiles UpdatePTUDevCtrl
SUBDIRS = DownloadDCFirmware DownloadDCJsonFiles SyncTariffs UpdatePTUDevCtrl

View File

@ -209,7 +209,7 @@ Update::sendNextDataBlock(QByteArray const &binary, int bNum) const {
QString s = nextTimePoint();
s += " sending block ";
s += QString("%1/%2 ...done <PROGRESS>").arg(bNum).arg(m_totalBlocks);
s += QString("%1/%2 ...done <DC-PROGRESS>").arg(bNum).arg(m_totalBlocks);
s += QString::number(ceil(((bNum * 100.0) / (double)m_totalBlocks)));
qInfo() << s.toUtf8().constData();

View File

@ -79,6 +79,7 @@ int main(int argc, char **argv) {
bool const showExtendedVersion = parser.extendedVersion();
bool const alwaysDownloadConfig = parser.alwaysDownloadConfig();
bool const alwaysDownloadDC = parser.alwaysDownloadDC();
Update::setPPid(parser.ppid());
QString const rtPath = QCoreApplication::applicationDirPath();
@ -88,29 +89,32 @@ int main(int argc, char **argv) {
QString const branchName = (zoneNr != 0)
? QString("zg1/zone%1").arg(zoneNr) : "master";
qInfo() << "pwd ......................" << rtPath;
qInfo() << "repositoryUrl ............" << repositoryUrl;
qInfo() << "plugInDir ................" << plugInDir;
qInfo() << "plugInName ..............." << plugInName;
qInfo() << "workingDir ..............." << workingDir;
qInfo() << "psaConfigDir ............." << psaConfigDir;
qInfo() << "psaTariffDir ............." << psaTariffDir;
qInfo() << "dryRun ..................." << dryRun;
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
qInfo() << "showYoctoVersion ........." << showYoctoVersion;
qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus;
qInfo() << "showExtendedVersion ......" << showExtendedVersion;
qInfo() << "iniFileName .............." << iniFileName;
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
qInfo() << "machineNr ................" << machineNr;
qInfo() << "customerNr ..............." << customerNr;
qInfo() << "zoneNr ..................." << zoneNr;
if (Update::ppid() == -1) {
qInfo() << "pwd ......................" << rtPath;
qInfo() << "repositoryUrl ............" << repositoryUrl;
qInfo() << "plugInDir ................" << plugInDir;
qInfo() << "plugInName ..............." << plugInName;
qInfo() << "workingDir ..............." << workingDir;
qInfo() << "psaConfigDir ............." << psaConfigDir;
qInfo() << "psaTariffDir ............." << psaTariffDir;
qInfo() << "dryRun ..................." << dryRun;
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
qInfo() << "showYoctoVersion ........." << showYoctoVersion;
qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus;
qInfo() << "showExtendedVersion ......" << showExtendedVersion;
qInfo() << "iniFileName .............." << iniFileName;
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
qInfo() << "machineNr ................" << machineNr;
qInfo() << "customerNr ..............." << customerNr;
qInfo() << "zoneNr ..................." << zoneNr;
qInfo() << "parent pid ..............." << Update::ppid();
if (showExtendedVersion) {
printf(APP_EXTENDED_VERSION"\n");
return 0;
if (showExtendedVersion) {
printf(APP_EXTENDED_VERSION"\n");
return 0;
}
}
QString const &customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
@ -121,7 +125,10 @@ int main(int argc, char **argv) {
if (mountPath.has_value()) {
filesToUpdate = System::getJsonFilesOnUsbStick(mountPath.value());
} else {
qCritical() << "Using customer repository" << customerRepo;
if (Update::ppid() == -1) {
qCritical() << "Using customer repository" << customerRepo;
}
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
if (dir.exists()) {
@ -146,13 +153,16 @@ int main(int argc, char **argv) {
plugInName,
workingDir);
update.doUpdate(filesToUpdate, mountPath.has_value());
update.checkJsonVersions();
update.doUpdate();
// update.doUpdate(filesToUpdate, mountPath.has_value());
// update.checkJsonVersions();
//update.checkJsonVersions(filesToUpdate);
if (mountPath.has_value()) {
System::umountUSBStick();
}
qInfo() << "<JS-UPDATE-FINISH>";
return 0;
}

View File

@ -21,10 +21,13 @@
#include <QDateTime>
#include <QPluginLoader>
#include <QMap>
#include <cmath>
#define UPDATE_OPKG (1)
#define UPDATE_DC (0)
qint64 Update::c_ppid = -1;
static const QMap<QString, int> baudrateMap = {
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
{"57600" , 4}, {"115200" , 5}
@ -104,7 +107,7 @@ Update::Update(QString customerRepository,
char const *serialInterface,
char const *baudrate)
: QObject(parent)
, m_hw(loadDCPlugin(QDir(plugInDir), pluginName))
// , m_hw(loadDCPlugin(QDir(plugInDir), pluginName))
, m_serialInterface(serialInterface)
, m_baudrate(baudrate)
, m_customerRepository(customerRepository)
@ -115,27 +118,65 @@ Update::Update(QString customerRepository,
, m_dryRun(dryRun)
, m_sys_areDCdataValid(false) {
if (!m_hw) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???";
} else {
int tries = 20;
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
// must deliver 'true', only then are all data from hwapi valid
if (--tries < 0) {
qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED";
break;
}
m_hw->dc_autoRequest(true);
QThread::msleep(500);
}
m_start = QDateTime::currentDateTime();
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_sys_areDCDataValid ..."
<< m_sys_areDCdataValid;
if (Update::ppid() == -1) {
if (!m_hw) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???";
} else {
int tries = 20;
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
// must deliver 'true', only then are all data from hwapi valid
if (--tries < 0) {
qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED";
break;
}
m_hw->dc_autoRequest(true);
QThread::msleep(500);
}
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_sys_areDCDataValid ..."
<< m_sys_areDCdataValid;
}
}
}
Update::~Update() {
unloadDCPlugin();
// unloadDCPlugin();
}
bool Update::doUpdate() {
int numberOfFiles = 3;
QString s = nextTimePoint();
s += " sending ";
s += QString("%1 ...done <JS-PROGRESS>").arg("DC2C_cash.json");
s += QString::number(ceil(((1 * 100.0) / (double)numberOfFiles)));
qInfo() << s.toUtf8().constData();
QThread::msleep(2000);
s = nextTimePoint();
s += " sending ";
s += QString("%1 ...done <JS-PROGRESS>").arg("DC2C_device.json");
s += QString::number(ceil(((2 * 100.0) / (double)numberOfFiles)));
qInfo() << s.toUtf8().constData();
QThread::msleep(2000);
s = nextTimePoint();
s += " sending ";
s += QString("%1 ...done <JS-PROGRESS>").arg("DC2C_print01.json");
s += QString::number(ceil(((3 * 100.0) / (double)numberOfFiles)));
qInfo() << s.toUtf8().constData();
QThread::msleep(2000);
return true;
}
bool Update::doUpdate(QStringList const &filesToWorkOn, bool usbStickDetected) {

View File

@ -8,6 +8,7 @@
#include <QByteArray>
#include <QProcess>
#include <QPluginLoader>
#include <QDateTime>
#include <initializer_list>
@ -36,6 +37,14 @@ class Update : public QObject {
static QPluginLoader pluginLoader;
QDateTime m_start;
QString nextTimePoint() const {
float const secs = m_start.msecsTo(QDateTime::currentDateTime()) / 1000.0;
return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0'));
}
static qint64 c_ppid;
public:
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6};
@ -44,6 +53,8 @@ public:
static bool unloadDCPlugin();
static QStringList split(QString line, QChar sep = ',');
static qint64 ppid() { return c_ppid; }
static void setPPid(qint64 ppid) { c_ppid = ppid; }
explicit Update(QString customerRepository,
QString customerNrStr,
@ -59,6 +70,7 @@ public:
virtual ~Update() override;
bool doUpdate(QStringList const &jsonFilesToDownload, bool usbStickDetected = false);
bool doUpdate();
bool updatePrinterTemplate(int templateIdx, QString fname) const;
bool updateConfig(QString jsFileToSendToDC);

View File

@ -0,0 +1,77 @@
QT += core
TARGET = ATBDownloadDCFirmware
VERSION="1.0.0"
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
INCLUDEPATH += \
plugins \
$${INCLUDEINTERFACES} \
$${_PRO_FILE_PWD_}/../UpdatePTUDevCtrl \
$${_PRO_FILE_PWD_}/../common/include
CONFIG += c++17
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
# keep comments, as /* fall through */
QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy -O
contains( CONFIG, PTU5 ) {
CONFIG += link_pkgconfig
QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
PTU5BASEPATH = /opt/devel/ptu5
INCLUDEPATH += $$PTU5BASEPATH/qt/libs/devicecontroller/include
LIBS += -L$$PTU5BASEPATH/qt/libs/devicecontroller/library
ARCH = PTU5
DEFINES+=PTU5
}
contains( CONFIG, PTU5_YOCTO ) {
QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
PTU5BASEPATH = /opt/devel/ptu5
ARCH = PTU5
DEFINES+=PTU5
}
contains( CONFIG, DesktopLinux ) {
# QMAKE_CC = ccache $$QMAKE_CC
# QMAKE_CXX = ccache $$QMAKE_CXX
QMAKE_CXXFLAGS += -std=c++17
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
ARCH = DesktopLinux
DEFINES+=DesktopLinux
}
SOURCES += \
main.cpp
# HEADERS += \
##########################################################################################
# for running program on target through QtCreator
contains( CONFIG, PTU5 ) {
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/app/tools/atbupdate/
!isEmpty(target.path): INSTALLS += target
}

14
SyncTariffs/main.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <QtGlobal>
#include <QCoreApplication>
#include <QByteArray>
#include <QProcess>
#include <QCommandLineParser>
#include <QStandardPaths>
#include <QSettings>
#include <QDir>
#include <QDebug>
int main(int argc, char **argv) {
return 0;
}

View File

@ -95,7 +95,13 @@ CommandLineParser::CommandLineParser()
QCommandLineOption(
QStringList() << "D" << "read-dc-version",
QCoreApplication::translate("main", "Show version of device controller."),
QCoreApplication::translate("main", "Show version of device controller."))) {
QCoreApplication::translate("main", "Show version of device controller.")))
, m_setPPid(
QCommandLineOption(
QStringList() << "P" << "set-ppid",
QCoreApplication::translate("main", "Set pid of parent process."),
QCoreApplication::translate("main", "Set pid of parent process."))) {
configure();
}
@ -154,6 +160,9 @@ void CommandLineParser::configure() {
m_readDCVersionOption.setDefaultValue("false");
m_parser.addOption(m_readDCVersionOption);
m_setPPid.setDefaultValue("-1");
m_parser.addOption(m_setPPid);
}
void CommandLineParser::readSettings() {
@ -286,6 +295,19 @@ QString CommandLineParser::workingDir() {
return m_workingDir;
}
qint64 CommandLineParser::ppid() {
m_ppid = -1;
if (m_parser.isSet(m_setPPid)) {
QString p = m_parser.value(m_setPPid);
bool ok;
qint64 q = p.toLongLong(&ok);
if (ok) {
m_ppid = q;
}
}
return m_ppid;
}
bool CommandLineParser::dryRun() {
if (m_parser.isSet(m_dryRunOption)) {
m_dryRun = m_parser.value(m_dryRunOption);

View File

@ -23,6 +23,7 @@ class CommandLineParser : public QCommandLineParser {
QString m_alwaysDownloadDC;
QString m_readDCVersion{"false"};
QString m_dcDir{"etc/dc/"};
qint64 m_ppid;
QCommandLineOption m_repositoryUrlOption;
QCommandLineOption m_iniFileDirectoryOption;
@ -41,6 +42,7 @@ class CommandLineParser : public QCommandLineParser {
QCommandLineOption m_yoctoInstallStatusOption;
QCommandLineOption m_dcDirectoryOption;
QCommandLineOption m_readDCVersionOption;
QCommandLineOption m_setPPid;
QCommandLineParser m_parser;
@ -63,6 +65,7 @@ public:
QString psaConfigDir();
QString psaTariffDir();
bool dryRun();
qint64 ppid();
bool noUpdatePsaHardware();
bool yoctoVersion();
bool yoctoInstallStatus();

View File

@ -87,10 +87,12 @@ int main(int argc, char *argv[]) {
if (v.isEmpty()) {
QString sshKeyFile("/opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig");
if (QFileInfo(sshKeyFile).exists()) {
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
return -1;
if (qgetenv("GIT_SSH_COMMAND").isNull()) {
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
return -1;
}
}
} else {
qCritical() << "ERROR ssh-key-file" << sshKeyFile << "does not exists. Exiting...";
@ -201,7 +203,7 @@ int main(int argc, char *argv[]) {
mw.showFullScreen();
// test
worker.dcUpdate();
worker.jsUpdate();
// worker.summary();
return a.exec();

View File

@ -83,6 +83,9 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
connect(m_worker, SIGNAL(showSummary(QString)),this,SLOT(onShowSummary(QString)));
connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit()));
connect(m_worker, SIGNAL(showDcDownload(QString)),this,SLOT(onShowDcDownload(QString)));
connect(m_worker, SIGNAL(showJsonDownload(QString)),this,SLOT(onShowJsonDownload(QString)));
connect(m_worker, SIGNAL(showTariffUpdate(QString)),this,SLOT(onShowTariffUpdate(QString)));
connect(m_worker, SIGNAL(showISMASChecks(QString)),this,SLOT(onShowISMASChecks(QString)));
connect(m_worker, SIGNAL(setDcDownloadProgress(int)),this,SLOT(onSetDcDownloadProgress(int)));
connect(m_worker, SIGNAL(enableExit()),this,SLOT(onEnableExit()));
connect(m_worker, SIGNAL(stopStartTimer()),this,SLOT(onStopStartTimer()));
@ -105,6 +108,7 @@ void MainWindow::onShowSummary(QString text) {
ui->updateLabel->setText(s);
ui->updateLabel->hide();
ui->stepLabel->hide();
ui->updateProgress->hide();
s += text;
ui->updateStatus->setText(s);
@ -114,10 +118,80 @@ void MainWindow::onSetDcDownloadProgress(int v) {
ui->updateProgress->setValue(v);
}
void MainWindow::onShowTariffUpdate(QString) {
ui->exit->setEnabled(false);
QString s = ui->stepLabel->text();
QString tmp("Install tariff files ");
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
ui->stepLabel->setText(s);
}
void MainWindow::onShowISMASChecks(QString) {
QString s = ui->stepLabel->text();
QString tmp("Check ISMAS connectivity ");
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
tmp = "Check update activation ";
len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
ui->stepLabel->setText(s);
}
void MainWindow::onShowJsonDownload(QString) {
ui->exit->setEnabled(false);
QString s = ui->stepLabel->text();
QString tmp("Send json files to dc-hardware ");
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
ui->stepLabel->setText(s);
}
void MainWindow::onShowDcDownload(QString version) {
m_targetDcVersion = version;
ui->exit->setEnabled(false);
ui->stepLabel->setText(QString("Device controller update. Target version: %1").arg(version).leftJustified(m_width-3));
// test
onShowISMASChecks("");
onShowTariffUpdate("");
onShowJsonDownload("");
QString s = ui->stepLabel->text();
QString tmp("Send dc-firmware to dc-hardware ");
int len = m_showLineLength - tmp.length();
while (--len > 0) {
tmp += "&nbsp;";
}
s += QString("%1 <font color='#33FF50'>[OK ]</font> (%2)").arg(tmp).arg(version);
ui->stepLabel->setText(s);
}
MainWindow::~MainWindow() {

View File

@ -52,6 +52,9 @@ public slots:
void onEnableExit();
void onDisableExit();
void onShowDcDownload(QString);
void onShowJsonDownload(QString);
void onShowTariffUpdate(QString);
void onShowISMASChecks(QString);
void onSetDcDownloadProgress(int);
void onShowSummary(QString);
#if EMERGENCY_LEAVE_BL==1
@ -68,6 +71,9 @@ private slots:
void onQuit();
private:
int const m_showLineLength = 37;
void scrollDownTextEdit();
void onShowMessage(QString, QString);

View File

@ -37,6 +37,7 @@ void Command::readyReadStandardOutput() {
QProcess *p = (QProcess *)sender();
if (p) {
QString s = p->readAllStandardOutput();
if (m_worker) {
int i = -1;
if ((i = s.indexOf("<DC-VERSION>")) != -1) {
@ -49,9 +50,9 @@ void Command::readyReadStandardOutput() {
}
emit m_worker->showDcDownload(s);
} else
if ((i = s.indexOf("<PROGRESS>")) != -1) {
if ((i = s.indexOf("<DC-PROGRESS>")) != -1) {
bool ok;
int v = s.mid(i+10).trimmed().toInt(&ok);
int v = s.mid(i+13).trimmed().toInt(&ok);
if (ok) {
emit m_worker->setDcDownloadProgress(v);
emit m_worker->insertText(s.mid(0,i) + "\n");
@ -67,6 +68,14 @@ void Command::readyReadStandardOutput() {
if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) {
m_worker->summary();
//qApp->exit(-1);
} else
if ((i = s.indexOf("<JS-PROGRESS>")) != -1) {
bool ok;
int v = s.mid(i+13).trimmed().toInt(&ok);
if (ok) {
emit m_worker->setDcDownloadProgress(v);
emit m_worker->insertText(s.mid(0,i) + "\n");
}
} else {
emit m_worker->insertText(s);
}
@ -93,6 +102,11 @@ void Command::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
}
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput()));
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
if (m_command.contains("ATBDownloadDCJsonFiles")) {
m_worker->dcUpdate();
}
}
bool Command::start(QString workingDirectory, QStringList args) {
@ -104,12 +118,16 @@ bool Command::start(QString workingDirectory, QStringList args) {
if (m_p != nullptr) {
delete m_p;
}
qCritical() << "COMMAND" << m_command << workingDirectory << args;
m_p = new QProcess(this);
m_p->setWorkingDirectory(workingDirectory);
m_p->setProcessChannelMode(QProcess::MergedChannels);
connect(m_p, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(m_p, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
connect(m_p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
if (!args.isEmpty()) {
m_p->start(m_command, args);

View File

@ -18,9 +18,99 @@
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
#include <QStringList>
#include <QDirIterator>
#include <fstream>
QVector<QPair<QString, QString>> Utils::installedJsonFiles(QDir const &customerDir) {
QVector<QPair<QString, QString>> vec;
QStringList fileList;
QDirIterator it(QDir::cleanPath(customerDir.absolutePath() + QDir::separator() + "etc/psa_config"));
while (it.hasNext()) {
QFileInfo const fi(it.next());
if (fi.fileName().startsWith("DC2C") && fi.fileName().endsWith(".json")) {
fileList << fi.absoluteFilePath();
}
}
fileList.sort();
QString const &current = QDir::current().absolutePath();
if (!QDir::setCurrent(customerDir.absolutePath())) {
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
<< "working directory to" << customerDir.absolutePath();
} else {
for (int i = 0; i < fileList.size(); ++i) {
QProcess p;
QStringList params;
params << "-c" << "git log -n 1 --pretty=format:%H -- " << fileList[i];
p.start("bash", params);
p.waitForFinished();
QString r = p.readAllStandardOutput().left(8);
vec.push_back(QPair<QString, QString>(QFileInfo(fileList[i]).fileName(), r));
}
if (!QDir::setCurrent(current)) {
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
<< "working directory to" << current;
}
}
return vec;
}
QVector<QPair<QString, QString>> Utils::installedTariffFiles(QDir const &customerDir) {
QVector<QPair<QString, QString>> vec;
QStringList fileList;
QDirIterator it(QDir::cleanPath(customerDir.absolutePath() + QDir::separator() + "etc/psa_tariff"));
while (it.hasNext()) {
QFileInfo const fi(it.next());
if (fi.fileName().startsWith("tariff") && fi.fileName().endsWith(".json")) {
fileList << fi.absoluteFilePath();
}
}
fileList.sort();
QString const &current = QDir::current().absolutePath();
if (!QDir::setCurrent(customerDir.absolutePath())) {
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
<< "working directory to" << customerDir.absolutePath();
} else {
for (int i = 0; i < fileList.size(); ++i) {
QProcess p;
QStringList params;
params << "-c" << "git log -n 1 --pretty=format:%H -- " << fileList[i];
qCritical() << current << "git log -n 1 --pretty=format:%H -- " << fileList[i];
p.start("bash", params);
p.waitForFinished();
QString r = p.readAllStandardOutput().left(8);
vec.push_back(QPair<QString, QString>(QFileInfo(fileList[i]).fileName(), r));
}
if (!QDir::setCurrent(current)) {
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
<< "working directory to" << current;
}
}
return vec;
}
QVector<QPair<QString, QString>> Utils::installedPackages() {
QVector<QPair<QString, QString>> vec;
if (QFile::exists("/usr/bin/ptuPackageVersions")) {
@ -165,7 +255,7 @@ QString Utils::getTariffInfo(QString fileName) {
}
QString Utils::zoneName(quint8 i) {
QString Utils::zoneName(quint8 /* i */) {
//static constexpr char const *zName[] = {
// "",
// "purple",

View File

@ -36,6 +36,8 @@ namespace Utils {
bool isATBQTRunning();
QVector<QPair<QString, QString>> installedPackages();
QVector<QPair<QString, QString>> installedJsonFiles(QDir const &customerDir);
QVector<QPair<QString, QString>> installedTariffFiles(QDir const &customerDir);
}
#endif // UTILS_H_INCLUDED

View File

@ -178,12 +178,15 @@ Worker::Worker(int customerNr,
, m_updateProcessRunning(true)
, m_mainWindow(nullptr) /* contains plugin */
, m_dcDownloadFirmware(new Command("/opt/app/tools/atbupdate/ATBDownloadDCFirmware --read-dc-version true"))
, m_dcDownloadJsonFiles(new Command(
QString("/opt/app/tools/atbupdate/ATBDownloadDCJsonFiles --set-ppid %1").arg(QCoreApplication::applicationPid())))
//, m_withoutIsmasDirectPort(true) /* useful for testing */ {
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
m_start = QDateTime::currentDateTime();
m_dcDownloadFirmware->setWorker(this);
m_dcDownloadJsonFiles->setWorker(this);
// TODO: turn object into singleton
instance = this;
@ -1511,6 +1514,10 @@ PSAInstalled Worker::getPSAInstalled() {
return psaInstalled;
}
bool Worker::jsUpdate() {
return m_dcDownloadJsonFiles->start("/opt/app/tools/atbupdate");
}
bool Worker::dcUpdate() {
return m_dcDownloadFirmware->start("/opt/app/tools/atbupdate");
}
@ -1520,6 +1527,9 @@ void Worker::summary() {
QString summary, first, second, line, tmp;
QVector<QPair<QString, QString>> vec = Utils::installedPackages();
vec.append(Utils::installedTariffFiles(m_customerRepository));
vec.append(Utils::installedJsonFiles(m_customerRepository));
int max_first = 0, max_second = 0;
for (int i = 0; i < vec.size(); ++i) {
max_first = std::max(max_first, vec[i].first.length());
@ -1584,4 +1594,5 @@ void Worker::summary() {
}
emit showSummary(summary);
emit enableExit();
}

View File

@ -191,6 +191,7 @@ class Worker : public QThread{
MainWindow *m_mainWindow;
Command *m_dcDownloadFirmware;
Command *m_dcDownloadJsonFiles;
bool m_withoutIsmasDirectPort;
QString m_apismVersion;
@ -460,6 +461,7 @@ public:
Update *update() { return m_update; }
Update const *update() const { return m_update; }
bool jsUpdate();
bool dcUpdate();
void summary();
QDateTime start() { return m_start; }
@ -478,6 +480,9 @@ signals:
void enableExit();
void disableExit();
void showDcDownload(QString);
void showJsonDownload(QString);
void showTariffUpdate(QString);
void showISMASChecks(QString);
void showSummary(QString);
void setDcDownloadProgress(int);