Compare commits
12 Commits
8db818f6cd
...
b25b66395f
Author | SHA1 | Date | |
---|---|---|---|
b25b66395f | |||
de9182bdc9 | |||
af83c11f73 | |||
7cdefc9b49 | |||
dd0d7790e0 | |||
b23314a1f3 | |||
9f1f41e4b6 | |||
522f86aaac | |||
13259ba86e | |||
63a959315b | |||
c05db3b323 | |||
bc21ede1a1 |
@ -1,6 +1,6 @@
|
||||
QT += core
|
||||
|
||||
TARGET = ExecOpkgCmds
|
||||
TARGET = ATBUpdateOpkg
|
||||
|
||||
VERSION="1.0.0"
|
||||
win32 {
|
||||
@ -64,9 +64,17 @@ contains( CONFIG, DesktopLinux ) {
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
||||
main.cpp \
|
||||
message_handler.cpp \
|
||||
../common/src/utils_internal.cpp \
|
||||
../common/src/command.cpp \
|
||||
opkg_command.cpp
|
||||
|
||||
# HEADERS += \
|
||||
HEADERS += \
|
||||
message_handler.h \
|
||||
../common/include/utils_internal.h \
|
||||
../common/include/command.h \
|
||||
opkg_command.h
|
||||
|
||||
##########################################################################################
|
||||
# for running program on target through QtCreator
|
||||
|
@ -4,11 +4,66 @@
|
||||
|
||||
#include <QProcess>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "utils_internal.h"
|
||||
#include "opkg_command.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
QByteArray const value = qgetenv("LC_ALL");
|
||||
if (value.isEmpty() || value != "C") {
|
||||
qputenv("LC_ALL", "C");
|
||||
}
|
||||
|
||||
openlog("ATB-UPDATE-OPKG", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
||||
|
||||
QCoreApplication a(argc, argv);
|
||||
QCoreApplication::setApplicationName("ATBUpdateOpkg");
|
||||
QCoreApplication::setApplicationVersion(APP_VERSION);
|
||||
|
||||
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
|
||||
atbInstallMessageHandler(nullptr);
|
||||
//atbInstallMessageHandler(atbDebugOutput);
|
||||
setDebugLevel(LOG_NOTICE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
QString s = "<OPKG>\n\naaa<OPKG>bbb<OPKG>ccc<OPKG>\n";
|
||||
QString m_standardOutput{};
|
||||
if (!s.isEmpty()) {
|
||||
m_standardOutput += s.replace(QChar('\n'), "");
|
||||
qCritical() << m_standardOutput;
|
||||
|
||||
int startIndex, endIndex{};
|
||||
while (((startIndex = m_standardOutput.indexOf("<OPKG>")) == 0) &&
|
||||
((endIndex = m_standardOutput.indexOf("<OPKG>", 1)) != -1)) {
|
||||
QString str = m_standardOutput.mid(0, endIndex);
|
||||
qCritical() << "str" << str << str.mid(6);
|
||||
m_standardOutput = m_standardOutput.mid(endIndex);
|
||||
// qCritical() << "m" << m_standardOutput;
|
||||
}
|
||||
qCritical() << "m" << m_standardOutput;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption noactionOption("noaction");
|
||||
QCommandLineOption verboseOption("verbose");
|
||||
parser.addOption(noactionOption);
|
||||
parser.addOption(verboseOption);
|
||||
parser.process(a);
|
||||
|
||||
bool noaction = parser.isSet(noactionOption);
|
||||
OpkgCommand opkgCmd(noaction);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
97
Opkg/message_handler.cpp
Executable file
97
Opkg/message_handler.cpp
Executable file
@ -0,0 +1,97 @@
|
||||
#include "message_handler.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <cstring>
|
||||
#include <QString>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageLogContext>
|
||||
|
||||
|
||||
static char const *DBG_NAME[] = { "DBG ", "WARN ", "CRIT ", "FATAL", "INFO " };
|
||||
static bool installedMsgHandler = false;
|
||||
static int debugLevel = LOG_NOTICE;
|
||||
|
||||
int getDebugLevel() { return debugLevel; }
|
||||
void setDebugLevel(int newDebugLevel) {
|
||||
debugLevel = newDebugLevel;
|
||||
}
|
||||
|
||||
bool messageHandlerInstalled() {
|
||||
return installedMsgHandler;
|
||||
}
|
||||
|
||||
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler) {
|
||||
installedMsgHandler = (handler != 0);
|
||||
static QtMessageHandler prevHandler = nullptr;
|
||||
if (handler) {
|
||||
prevHandler = qInstallMessageHandler(handler);
|
||||
return prevHandler;
|
||||
} else {
|
||||
return qInstallMessageHandler(prevHandler);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Print message according to given debug level.
|
||||
///
|
||||
/// \note Install this function using qInstallMsgHandler().
|
||||
///
|
||||
/// int main(int argc, char **argv) {
|
||||
/// installMsgHandler(atbDebugOutput);
|
||||
/// QApplication app(argc, argv);
|
||||
/// ...
|
||||
/// return app.exec();
|
||||
/// }
|
||||
///
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
||||
Q_UNUSED(context);
|
||||
QString const localMsg = QString(DBG_NAME[type]) + msg.toLocal8Bit();
|
||||
|
||||
switch (debugLevel) {
|
||||
case LOG_DEBUG: { // debug-level message
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
} break;
|
||||
case LOG_INFO: { // informational message
|
||||
if (type != QtDebugMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_NOTICE: { // normal, but significant, condition
|
||||
if (type != QtDebugMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_WARNING: { // warning conditions
|
||||
if (type != QtInfoMsg && type != QtDebugMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_ERR: { // error conditions
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_CRIT: { // critical conditions
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_ALERT: { // action must be taken immediately
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_EMERG: { // system is unusable
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
syslog(LOG_DEBUG, "%s", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
//fprintf(stderr, "%s No ErrorLevel defined! %s\n",
|
||||
// datetime.toStdString().c_str(), msg.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
23
Opkg/message_handler.h
Executable file
23
Opkg/message_handler.h
Executable file
@ -0,0 +1,23 @@
|
||||
#ifndef MESSAGE_HANDLER_H_INCLUDED
|
||||
#define MESSAGE_HANDLER_H_INCLUDED
|
||||
|
||||
#include <QtGlobal>
|
||||
#ifdef __linux__
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
int getDebugLevel();
|
||||
void setDebugLevel(int newDebugLevel);
|
||||
|
||||
bool messageHandlerInstalled();
|
||||
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler);
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
// typedef void (*QtMessageHandler)(QtMsgType, const char *);
|
||||
void atbDebugOutput(QtMsgType type, const char *msg);
|
||||
#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
// typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
|
||||
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
#endif
|
||||
|
||||
#endif // MESSAGE_HANDLER_H_INCLUDED
|
176
Opkg/opkg_command.cpp
Normal file
176
Opkg/opkg_command.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
#include "opkg_command.h"
|
||||
|
||||
#include "command.h"
|
||||
#include "utils_internal.h"
|
||||
using namespace internal;
|
||||
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QFlags>
|
||||
#include <QRegularExpression>
|
||||
|
||||
OpkgCommand::OpkgCommand(bool noaction, QString const &opkg_commands_filename)
|
||||
: m_noaction(noaction)
|
||||
, m_opkg_commands_filename(opkg_commands_filename) {
|
||||
cleanUpOpkgCache();
|
||||
execCommandsInternal();
|
||||
}
|
||||
|
||||
bool OpkgCommand::readCommands() {
|
||||
QFile opkgFile(QDir::cleanPath(m_opkg_commands_dir + QDir::separator() + m_opkg_commands_filename));
|
||||
if (!opkgFile.exists()) {
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< opkgFile.fileName() << "does not exists";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_commands.clear();
|
||||
|
||||
if (opkgFile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream in(&opkgFile);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
// TODO: "^\\s*[#]{0,}$" : empty line or comment line starting with #
|
||||
static const QRegularExpression comment("^\\s*[#].*$");
|
||||
static const QRegularExpression emptyLine("^\\s*$");
|
||||
if (line.indexOf(emptyLine, 0) == -1 &&
|
||||
line.indexOf(comment, 0) == -1) {
|
||||
QString const &commandLine = line.trimmed();
|
||||
if (!commandLine.isEmpty()) {
|
||||
m_commands << commandLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "error opening" << opkgFile.fileName();
|
||||
}
|
||||
|
||||
return m_commands.size() > 0;
|
||||
}
|
||||
|
||||
bool OpkgCommand::execCommandsInternal() {
|
||||
if (readCommands()) {
|
||||
// command lines are located between markers: <OPKG>...<OPKG>
|
||||
// they are later removed when used by the update-tool.
|
||||
qCritical().noquote() << "<OPKG>";
|
||||
QListIterator<QString> it(m_commands);
|
||||
while (it.hasNext()) {
|
||||
QString command = it.next();
|
||||
QStringList cmdAndOptions = command.split(u' ', QString::SkipEmptyParts);
|
||||
if (cmdAndOptions.size() > 0) {
|
||||
QString const &cmd = cmdAndOptions.takeFirst();
|
||||
if (m_noaction) {
|
||||
if (cmd.contains("opkg")) {
|
||||
cmdAndOptions.prepend("--noaction");
|
||||
} else continue; // only opkg has the --noaction option
|
||||
}
|
||||
QStringList const &options = cmdAndOptions;
|
||||
if (exec(cmd, options)) {
|
||||
qCritical().noquote() << cmd << options.join(" ") << "ok" << "<OPKG>";
|
||||
} else {
|
||||
qCritical().noquote() << cmd << options.join(" ") << "FAIL" << "<OPKG>";
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool OpkgCommand::execCommands() {
|
||||
if (readCommands()) {
|
||||
QListIterator<QString> it(m_commands);
|
||||
while (it.hasNext()) {
|
||||
QString command = it.next();
|
||||
QStringList cmdAndOptions = command.split(u' ', QString::SkipEmptyParts);
|
||||
if (cmdAndOptions.size() > 0) {
|
||||
QString const &cmd = cmdAndOptions.takeFirst();
|
||||
if (m_noaction) {
|
||||
cmdAndOptions.prepend("--noaction");
|
||||
}
|
||||
QStringList const &options = cmdAndOptions;
|
||||
if (exec(cmd, options)) {
|
||||
qCritical().noquote() << cmd << options.join(" ");
|
||||
} else {
|
||||
qCritical().noquote() << cmd << options.join(" ") << "FAIL";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
#if 0
|
||||
|
||||
QFile opkgFile(QDir::cleanPath(m_opkg_commands_dir + QDir::separator() + m_opkg_commands_filename));
|
||||
if (!opkgFile.exists()) {
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< opkgFile.fileName() << "does not exists";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (opkgFile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream in(&opkgFile);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
// TODO: "^\\s*[#]{0,}$" : empty line or comment line starting with #
|
||||
static const QRegularExpression comment("^\\s*[#].*$");
|
||||
static const QRegularExpression emptyLine("^\\s*$");
|
||||
if (line.indexOf(emptyLine, 0) == -1 &&
|
||||
line.indexOf(comment, 0) == -1) {
|
||||
QString const &commandLine = line.trimmed();
|
||||
if (!commandLine.isEmpty()) {
|
||||
QStringList cmdAndOptions = commandLine.split(u' ', QString::SkipEmptyParts);
|
||||
if (cmdAndOptions.size() > 0) {
|
||||
QString const &cmd = cmdAndOptions.takeFirst();
|
||||
if (m_noaction) {
|
||||
cmdAndOptions.prepend("--noaction");
|
||||
}
|
||||
QStringList const &options = cmdAndOptions;
|
||||
if (exec(cmd, options)) {
|
||||
qCritical().noquote() << cmd << options.join(" ") << "ok";
|
||||
} else {
|
||||
qCritical().noquote() << cmd << options.join(" ") << "FAIL";
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "error opening" << opkgFile.fileName();
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OpkgCommand::exec(QString const &cmd, QStringList const &options,
|
||||
int start_timeout, int finish_timeout) {
|
||||
bool const verbose = false;
|
||||
return Command(cmd, options, "/tmp", verbose, start_timeout, finish_timeout).exec();
|
||||
}
|
||||
|
||||
bool OpkgCommand::cleanUpOpkgCache() {
|
||||
bool removedFiles = true;
|
||||
QDir dir("/var/cache/opkg/");
|
||||
if (dir.exists()) {
|
||||
dir.setNameFilters(QStringList() << ".gz" << ".ipk");
|
||||
dir.setFilter(QDir::Files);
|
||||
foreach(QString dirFile, dir.entryList()) {
|
||||
removedFiles &= dir.remove(dirFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (removedFiles == false) {
|
||||
qCritical() << "some errors while cleaning up opkg-cache";
|
||||
}
|
||||
|
||||
return removedFiles;
|
||||
}
|
29
Opkg/opkg_command.h
Normal file
29
Opkg/opkg_command.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef OPKG_COMMND_H_INCLUDED
|
||||
#define OPKG_COMMND_H_INCLUDED
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
class OpkgCommand {
|
||||
QString const m_opkg_commands_dir{"/etc/psa_update/"};
|
||||
bool m_noaction;
|
||||
QString m_opkg_commands_filename;
|
||||
QStringList m_commands;
|
||||
|
||||
bool execCommands();
|
||||
bool execCommandsInternal();
|
||||
bool cleanUpOpkgCache();
|
||||
|
||||
public:
|
||||
OpkgCommand(bool noaction = false,
|
||||
QString const &opkg_commands_file_name="opkg_commands");
|
||||
|
||||
bool exec(QString const &cmd, QStringList const &options,
|
||||
int start_timeout = 100000, int finish_timeout = 100000);
|
||||
|
||||
QStringList commands() { return m_commands; }
|
||||
QStringList const &commands() const { return m_commands; }
|
||||
|
||||
bool readCommands();
|
||||
};
|
||||
|
||||
#endif // OPKG_COMMND_H_INCLUDED
|
@ -95,6 +95,8 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
connect(m_worker, SIGNAL(showUpdateRequest(QString)),this,SLOT(onShowUpdateRequest(QString)));
|
||||
connect(m_worker, SIGNAL(showCustRepoStatus(QString)),this,SLOT(onShowCustRepoStatus(QString)));
|
||||
connect(m_worker, SIGNAL(showExecOpkgStatus(QString)),this,SLOT(onShowExecOpkgStatus(QString)));
|
||||
connect(m_worker, SIGNAL(showExecOpkgCommand(QString)),this,SLOT(onShowExecOpkgCommand(QString)));
|
||||
connect(m_worker, SIGNAL(showExecOpkgOverallResult(QString, bool)),this,SLOT(onShowExecOpkgOverallResult(QString,bool)));
|
||||
connect(m_worker, SIGNAL(showDownloadDCJsonFilesStatus(QString)),this,SLOT(onShowDownloadDCJsonFilesStatus(QString)));
|
||||
connect(m_worker, SIGNAL(showSyncCustRepoStatus(QString)),this,SLOT(onShowSyncCustRepoStatus(QString)));
|
||||
connect(m_worker, SIGNAL(showUpdateDCFirmware(QString)),this,SLOT(onShowUpdateDCFirmware(QString)));
|
||||
@ -149,11 +151,12 @@ void MainWindow::onShowTariffUpdate(QString) {
|
||||
void MainWindow::onShowISMASConnectivity(QString status) {
|
||||
// ausgabe: connected, not connected, connecting
|
||||
|
||||
m_stepLabelChopCount = 0;
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
|
||||
QString tmp("backend connection (ISMAS) ");
|
||||
QString tmp("Check backend connection (ISMAS) ");
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
@ -184,6 +187,10 @@ void MainWindow::onShowISMASConnectivity(QString status) {
|
||||
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
|
||||
}
|
||||
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Check update request";
|
||||
m_stepLabelChopCount += s.length();
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
@ -191,8 +198,9 @@ void MainWindow::onShowCustRepoStatus(QString status) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
s.chop(m_stepLabelChopCount);
|
||||
|
||||
QString tmp("customer repository ");
|
||||
QString tmp("Check customer repository ");
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
@ -204,6 +212,10 @@ void MainWindow::onShowCustRepoStatus(QString status) {
|
||||
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
|
||||
}
|
||||
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Install SW packets (dry run)";
|
||||
m_stepLabelChopCount += s.length();
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
@ -228,12 +240,57 @@ void MainWindow::onShowExecOpkgStatus(QString status) {
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
void MainWindow::onShowExecOpkgCommand(QString cmd) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "cmd" << cmd;
|
||||
|
||||
if (cmd.back() != QChar('\n')) {
|
||||
cmd += "\n";
|
||||
}
|
||||
onInsertText(cmd);
|
||||
}
|
||||
|
||||
void MainWindow::onShowExecOpkgOverallResult(QString status, bool noaction) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
s.chop(m_stepLabelChopCount);
|
||||
|
||||
QString tmp = noaction ? "Install SW packets (dry run) " : "Install SW packets ";
|
||||
int len = m_showLineLength - tmp.length();
|
||||
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
|
||||
if (status.contains(internal::EXEC_OPKG_COMMANDS_SUCCESS, Qt::CaseInsensitive)) {
|
||||
s += QString("%1 <font color='Green'>success</font><br />").arg(tmp);
|
||||
} else
|
||||
if (status.contains(internal::EXEC_OPKG_COMMANDS_FAIL, Qt::CaseInsensitive)) {
|
||||
s += QString("%1 <font color='Red'>%2</font><br />").arg(tmp).arg(internal::EXEC_OPKG_COMMANDS_FAIL);
|
||||
} else {
|
||||
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
|
||||
}
|
||||
|
||||
if (noaction) {
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Install SW packets";
|
||||
m_stepLabelChopCount += s.length();
|
||||
} else {
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Install DC configuration";
|
||||
m_stepLabelChopCount += s.length();
|
||||
}
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
void MainWindow::onShowDownloadDCJsonFilesStatus(QString status) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
s.chop(m_stepLabelChopCount);
|
||||
|
||||
QString tmp = "configure device controller ";
|
||||
QString tmp = "Install DC configuration ";
|
||||
int len = m_showLineLength - tmp.length();
|
||||
|
||||
while (--len > 0) {
|
||||
@ -246,6 +303,10 @@ void MainWindow::onShowDownloadDCJsonFilesStatus(QString status) {
|
||||
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
|
||||
}
|
||||
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Synchronize repository/filesystem";
|
||||
m_stepLabelChopCount += s.length();
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
@ -253,8 +314,9 @@ void MainWindow::onShowSyncCustRepoStatus(QString status) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
s.chop(m_stepLabelChopCount);
|
||||
|
||||
QString tmp = "synchronize repository/filesystem ";
|
||||
QString tmp = "Synchronize repository/filesystem ";
|
||||
int len = m_showLineLength - tmp.length();
|
||||
|
||||
while (--len > 0) {
|
||||
@ -267,6 +329,10 @@ void MainWindow::onShowSyncCustRepoStatus(QString status) {
|
||||
s += QString( "%1 <font color='Red'>UNKNOWN STATUS</font><br />").arg(tmp);
|
||||
}
|
||||
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Update DC";
|
||||
m_stepLabelChopCount += s.length();
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
@ -274,8 +340,9 @@ void MainWindow::onShowUpdateDCFirmware(QString status) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
s.chop(m_stepLabelChopCount);
|
||||
|
||||
QString tmp = "device controller update ";
|
||||
QString tmp = "Update DC ";
|
||||
int len = m_showLineLength - tmp.length();
|
||||
|
||||
while (--len > 0) {
|
||||
@ -297,8 +364,9 @@ void MainWindow::onShowUpdateRequest(QString status) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << "status" << status;
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
s.chop(m_stepLabelChopCount);
|
||||
|
||||
QString tmp = "update request ";
|
||||
QString tmp = "Check update request ";
|
||||
int len = m_showLineLength - tmp.length();
|
||||
|
||||
while (--len > 0) {
|
||||
@ -330,6 +398,10 @@ void MainWindow::onShowUpdateRequest(QString status) {
|
||||
s += QString( "%1 <font color='Red'>UNKNOWN</font><br />").arg(tmp);
|
||||
}
|
||||
|
||||
m_stepLabelChopCount = -s.length();
|
||||
s += "Check customer repository";
|
||||
m_stepLabelChopCount += s.length();
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,8 @@ public slots:
|
||||
void onShowUpdateRequest(QString);
|
||||
void onShowCustRepoStatus(QString);
|
||||
void onShowExecOpkgStatus(QString);
|
||||
void onShowExecOpkgCommand(QString);
|
||||
void onShowExecOpkgOverallResult(QString,bool);
|
||||
void onShowDownloadDCJsonFilesStatus(QString);
|
||||
void onShowSyncCustRepoStatus(QString);
|
||||
void onShowUpdateDCFirmware(QString);
|
||||
@ -94,5 +96,6 @@ private:
|
||||
UpdateDcEvent::UpdateStep m_updateStep;
|
||||
QTimer *m_statusTimer;
|
||||
QString m_targetDcVersion;
|
||||
int m_stepLabelChopCount{};
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include "process/exec_opkg_command.h"
|
||||
#include "worker.h"
|
||||
#include "utils_internal.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
ExecOpkgCommand::ExecOpkgCommand(QString const &command,
|
||||
Worker *worker,
|
||||
@ -8,23 +11,75 @@ ExecOpkgCommand::ExecOpkgCommand(QString const &command,
|
||||
int start_timeout,
|
||||
int finish_timeout)
|
||||
: UpdateCommand(command, worker, nextCommandIndex, start_timeout, finish_timeout)
|
||||
, m_noaction(noaction) {
|
||||
, m_noaction(noaction)
|
||||
, m_ok_count{0}
|
||||
, m_fail_count{0} {
|
||||
}
|
||||
|
||||
void ExecOpkgCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
QProcess *p = (QProcess *)sender();
|
||||
if (p) {
|
||||
Worker *w = worker();
|
||||
if (w) {
|
||||
if (m_fail_count == 0 && m_ok_count > 0) {
|
||||
emit w->showExecOpkgOverallResult(internal::EXEC_OPKG_COMMANDS_SUCCESS, m_noaction);
|
||||
} else
|
||||
if (m_ok_count == 0 && m_fail_count > 0) {
|
||||
emit w->showExecOpkgOverallResult(internal::EXEC_OPKG_COMMANDS_FAIL, m_noaction);
|
||||
} else {
|
||||
// TODO
|
||||
emit w->showExecOpkgOverallResult(internal::EXEC_OPKG_COMMANDS_SUCCESS, m_noaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
return UpdateCommand::finished(exitCode, exitStatus);
|
||||
}
|
||||
|
||||
void ExecOpkgCommand::readyReadStandardOutput() {
|
||||
QProcess *p = (QProcess *)sender();
|
||||
if (p) {
|
||||
QString s = p->readAllStandardOutput();
|
||||
|
||||
// TODO
|
||||
Worker *w = worker();
|
||||
if (w) {
|
||||
// static constexpr const char *EXEC_OPKG_COMMANDS_SUCCESS{"success"};
|
||||
emit w->showExecOpkgStatus(UpdateCommand::EXEC_OPKG_COMMANDS_SUCCESS);
|
||||
QString s = p->readAllStandardOutput().trimmed();
|
||||
if (!s.isEmpty()) {
|
||||
m_standardOutput += s.replace(QChar('\n'), "");
|
||||
|
||||
// the command lines in etc/psa_update/opkg_commands are
|
||||
// separated by "<OPKG>" markers. Note that the file opkg_commands
|
||||
// itself is *not* changed, of course.
|
||||
|
||||
int startIndex, endIndex{};
|
||||
while (((startIndex = m_standardOutput.indexOf(internal::OPKG_MARKER)) == 0) &&
|
||||
((endIndex = m_standardOutput.indexOf(internal::OPKG_MARKER, 1)) != -1)) {
|
||||
|
||||
QString result = m_standardOutput.mid(0, endIndex).mid(6);
|
||||
m_standardOutput = m_standardOutput.mid(endIndex);
|
||||
|
||||
if (!s.isEmpty()) {
|
||||
QStringList const lst = result.split(u' ', QString::SkipEmptyParts);
|
||||
|
||||
if (lst.size() >= 2) {
|
||||
if (lst.last() == "ok") {
|
||||
m_ok_count += 1;
|
||||
if (lst.contains("noaction")) {
|
||||
emit w->showExecOpkgCommand(result);
|
||||
} else {
|
||||
emit w->showExecOpkgCommand(result);
|
||||
}
|
||||
} else {
|
||||
m_fail_count += 1;
|
||||
if (lst.contains("noaction")) {
|
||||
emit w->showExecOpkgCommand(result);
|
||||
} else {
|
||||
emit w->showExecOpkgCommand(result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emit w->showExecOpkgCommand(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,9 @@
|
||||
|
||||
class ExecOpkgCommand : public UpdateCommand {
|
||||
bool m_noaction{false};
|
||||
QString m_standardOutput{};
|
||||
int m_ok_count{};
|
||||
int m_fail_count{};
|
||||
public:
|
||||
explicit ExecOpkgCommand(QString const &command,
|
||||
Worker *worker,
|
||||
|
@ -229,15 +229,17 @@ Worker::Worker(int customerNr,
|
||||
// NOTE: first run the opkg commands with no action -> dry-run
|
||||
m_workList.push_back(
|
||||
std::make_unique<ExecOpkgCommand>(
|
||||
QString("echo ExecOpkgCommand dry-run")
|
||||
// QString("echo ExecOpkgCommand noaction")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateOpkg --noaction")
|
||||
, this, ++next, true));
|
||||
|
||||
// *** exec opkg-commands ***
|
||||
// NOTE: first run the opkg commands with action -> no dry-run
|
||||
m_workList.push_back(
|
||||
std::make_unique<ExecOpkgCommand>(
|
||||
QString("echo ExecOpkgCommand run")
|
||||
, this, ++next, true));
|
||||
//QString("echo ExecOpkgCommand run")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateOpkg")
|
||||
, this, ++next, false));
|
||||
|
||||
// *** send json files down to device controller ***
|
||||
m_workList.push_back(
|
||||
|
@ -497,6 +497,8 @@ signals:
|
||||
void showCustRepoStatus(QString);
|
||||
void showUpdateRequest(QString);
|
||||
void showExecOpkgStatus(QString);
|
||||
void showExecOpkgCommand(QString);
|
||||
void showExecOpkgOverallResult(QString,bool);
|
||||
void showDownloadDCJsonFilesStatus(QString);
|
||||
void showSyncCustRepoStatus(QString);
|
||||
void showUpdateDCFirmware(QString);
|
||||
|
@ -16,6 +16,7 @@ class Command : public QObject {
|
||||
|
||||
int m_waitForStartTimeout;
|
||||
int m_waitForFinishTimeout;
|
||||
bool m_verbose;
|
||||
int m_exitCode;
|
||||
QString m_workingDirectory;
|
||||
|
||||
@ -27,6 +28,7 @@ public:
|
||||
Command(QString command,
|
||||
QStringList args,
|
||||
QString workingDirectory,
|
||||
bool verbose = true,
|
||||
int start_timeout = 100000,
|
||||
int finish_timeout = 100000);
|
||||
|
||||
|
@ -18,10 +18,15 @@ namespace internal {
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_PULL_ERROR{"pull error"};
|
||||
static constexpr const char *GIT_CUSTOMER_REPO_UP_TO_DATE{"up to date"};
|
||||
static constexpr const char *EXEC_OPKG_COMMANDS_SUCCESS{"success"};
|
||||
static constexpr const char *EXEC_OPKG_COMMANDS_FAIL{"FAIL"};
|
||||
static constexpr const char *EXEC_OPKG_COMMANDS_NOACTION_SUCCESS{"success"};
|
||||
static constexpr const char *EXEC_OPKG_COMMANDS_NOACTION_FAIL{"FAIL"};
|
||||
static constexpr const char *UPDATE_DC_JSON_FILES_SUCCESS{"success"};
|
||||
static constexpr const char *SYNC_CUSTOMER_REPO_FILES_SUCCESS{"success"};
|
||||
static constexpr const char *UPDATE_DC_FIRMARE_SUCCESS{"success"};
|
||||
|
||||
static constexpr const char *OPKG_MARKER{"<OPKG>"};
|
||||
|
||||
int read1stLineOfFile(QString fileName);
|
||||
QString customerRepoRoot();
|
||||
QString customerRepoDir();
|
||||
|
@ -7,11 +7,12 @@
|
||||
#include <QDateTime>
|
||||
|
||||
Command::Command(QString command, QStringList args, QString workingDirectory,
|
||||
int start_timeout, int finish_timeout)
|
||||
bool verbose, int start_timeout, int finish_timeout)
|
||||
: m_command(command.trimmed())
|
||||
, m_commandResult("")
|
||||
, m_waitForStartTimeout(start_timeout)
|
||||
, m_waitForFinishTimeout(finish_timeout)
|
||||
, m_verbose(verbose)
|
||||
, m_exitCode(-1)
|
||||
, m_workingDirectory(workingDirectory)
|
||||
, m_args(args) {
|
||||
@ -28,7 +29,10 @@ Command::Command(QString command, QStringList args, QString workingDirectory,
|
||||
void Command::readyReadStandardOutput() {
|
||||
QProcess *p = (QProcess *)sender();
|
||||
if (p) {
|
||||
qCritical().noquote() << p->readAllStandardOutput();
|
||||
QString s = p->readAllStandardOutput();
|
||||
if (m_verbose) {
|
||||
qCritical().noquote() << s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user