Compare commits
47 Commits
4b9dcc5e99
...
4b3a39b0e6
Author | SHA1 | Date | |
---|---|---|---|
4b3a39b0e6 | |||
a44b780d93 | |||
19dfae9b56 | |||
bef0d4fe12 | |||
72a2fc781c | |||
fc264689b1 | |||
fc587456d5 | |||
a2b933ab71 | |||
7d0fdf4d6d | |||
c2ce44c79b | |||
16a9556863 | |||
48896f97ec | |||
4486317cb2 | |||
6b9b88ea19 | |||
99a99d95a1 | |||
d4ddbbee21 | |||
34e5189945 | |||
c44c805238 | |||
196f1a730e | |||
7dc04c4422 | |||
5efac2619b | |||
9b0f741b9b | |||
81c5f8ee7e | |||
29e6a25e72 | |||
5abc057bda | |||
8aeb7ecfea | |||
4bb8e241b6 | |||
4469a23f9c | |||
d1f795e2db | |||
6865056f4b | |||
37bd5c90d3 | |||
fcba120dfa | |||
1d4f50fb9f | |||
a78040a037 | |||
9b175d7789 | |||
2d7f145a25 | |||
4589c4ca76 | |||
a32258a59e | |||
22f25e5251 | |||
258d883a51 | |||
504e242d42 | |||
731cdcbe09 | |||
b4e2d4c54a | |||
42961dea40 | |||
fd2f601f67 | |||
b45af505cd | |||
2dfe80b654 |
@ -35,6 +35,42 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
# Fix display of UPDATE_SUCCESS when opkg_command fails. Detected when
|
||||
# updating apsim failed.
|
||||
# 1.3.11: Integrate version of ATBUpdateTool in SendLastVersion-ISMAS-message.
|
||||
# 1.3.12: Add command parameters for output of yocto-infos about ATBUpdateTool.
|
||||
# Use 'git pull' instead of 'git fetch'.
|
||||
# Use 'git clone --filter=blob:none' instead of 'git clone' to speed
|
||||
# up cloning of customer repository.
|
||||
# 1.3.13: Fix: if the customer repository is corrupted, remove it and re-clone
|
||||
# the repository (without checking the ISMAS-trigger (WAIT-)button.
|
||||
VERSION="1.3.14"
|
||||
# 1.3.14: Add additional check for sanity of customer repository using
|
||||
# "git fsck".
|
||||
# Stream-lined code of update process: massive refactoring.
|
||||
# Added functionality: If WAIT button is not active, then an existing
|
||||
# customer repository will be repaired, or a not existing repository
|
||||
# will be cloned. The process stops then.
|
||||
# However, if the WAIT button is active, the at least the commands in
|
||||
# opkg_commands will be executed. Changed files in the customer
|
||||
# repository will be worked on: tariff-files will be synced with the
|
||||
# local filesystem, json-files will be downloaded to firmware.
|
||||
# The device-controller firmware will be handled in a later version.
|
||||
|
||||
# PLANNED TODOS:
|
||||
# 1: Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT.
|
||||
# 2: Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu
|
||||
# geklont), aber zusaetzlich werden alle verfuegbaren Dateien als neu
|
||||
# angesehen und die entsprechenden Aktionen durchgefuehrt: tariff-files
|
||||
# spiegeln, json-files laden und dc laden. Also VORSICHT: das repository
|
||||
# muss in diesem fall wirklich in ordnung sein.
|
||||
# 3: Wurde keine Datei geaendert, kein initiales Clone und der WAIT-button
|
||||
# nicht aktiv, so (passiert natuerlich nichts) kann man davon ausgehen,
|
||||
# dass es sich um ein automatisches Update handelt. Dann koennte man im
|
||||
# ISMAS eine entsprechende Meldung anzeigen als Teil von SEND-LAST-VERSION.
|
||||
# Wenn der WAIT-button aktiv ist, dann werden zumindest die opkg-commands
|
||||
# ausgefuehrt.
|
||||
# 4: rsync: immer alle Dateien soiegeln (bis auf opkg-commands)
|
||||
# 5: Falls das Tool mal abstuerzt, dann einen Signal-Handler (fuer TERM)
|
||||
# installieren, sodass zumnidest SEND-LASt-VERSION mit rausgeht.
|
||||
# 6: rsync: explizites Binary, nicht das in busybox enthaltene.
|
||||
|
||||
win32 {
|
||||
BUILD_DATE=$$system("date /t")
|
||||
@ -46,7 +82,6 @@ win32 {
|
||||
|
||||
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
|
||||
|
||||
VERSION="1.3.11"
|
||||
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
|
||||
|
||||
INCLUDEPATH += plugins
|
||||
@ -59,6 +94,8 @@ 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
|
||||
|
||||
@ -67,14 +104,14 @@ contains( CONFIG, PTU5 ) {
|
||||
CONFIG += link_pkgconfig
|
||||
lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport
|
||||
QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7
|
||||
QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
ARCH = PTU5
|
||||
DEFINES+=PTU5
|
||||
}
|
||||
contains( CONFIG, PTU5_YOCTO ) {
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
|
||||
QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7
|
||||
QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
PTU5BASEPATH = /opt/devel/ptu5
|
||||
ARCH = PTU5
|
||||
DEFINES+=PTU5
|
||||
@ -88,7 +125,7 @@ contains( CONFIG, DesktopLinux ) {
|
||||
# QMAKE_CC = ccache $$QMAKE_CC
|
||||
# QMAKE_CXX = ccache $$QMAKE_CXX
|
||||
QMAKE_CXXFLAGS += -std=c++17
|
||||
QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
|
||||
ARCH = DesktopLinux
|
||||
DEFINES+=DesktopLinux
|
||||
|
@ -26,29 +26,93 @@ GitClient::GitClient(QString const &customerNrStr,
|
||||
}
|
||||
|
||||
bool GitClient::gitCloneCustomerRepository() {
|
||||
QString gitCommand("git clone ");
|
||||
/* Blobless clone
|
||||
==============
|
||||
|
||||
When using the --filter=blob:none option, the initial git clone will
|
||||
download all reachable commits and trees, and only download the blobs
|
||||
for commits when you do a git checkout. This includes the first checkout
|
||||
inside the git clone operation.
|
||||
|
||||
The important thing to notice is that we have a copy of every blob at
|
||||
HEAD but the blobs in the history are not present. If your repository
|
||||
has a deep history full of large blobs, then this option can
|
||||
significantly reduce your git clone times. The commit and tree data is
|
||||
still present, so any subsequent git checkout only needs to download
|
||||
the missing blobs. The Git client knows how to batch these requests to
|
||||
ask the server only for the missing blobs.
|
||||
|
||||
Further, when running git fetch in a blobless clone, the server only
|
||||
sends the new commits and trees. The new blobs are downloaded only
|
||||
after a git checkout. Note that git pull runs git fetch and then git
|
||||
merge, so it will download the necessary blobs during the git merge
|
||||
command.
|
||||
|
||||
When using a blobless clone, you will trigger a blob download whenever
|
||||
you need the contents of a file, but you will not need one if you only
|
||||
need the OID (object-id) of a file. This means that git log can detect
|
||||
which commits changed a given path without needing to download extra
|
||||
data.
|
||||
|
||||
This means that blobless clones can perform commands like git
|
||||
merge-base, git log, or even git log -- <path> with the same performance
|
||||
as a full clone.
|
||||
|
||||
Commands like git diff or git blame <path> require the contents of the
|
||||
paths to compute diffs, so these will trigger blob downloads the first
|
||||
time they are run. However, the good news is that after that you will
|
||||
have those blobs in your repository and do not need to download them a
|
||||
second time. Most developers only need to run git blame on a small
|
||||
number of files, so this tradeoff of a slightly slower git blame command
|
||||
is worth the faster clone and fetch times.
|
||||
|
||||
Note: git v2.18 does not support treeless clones: --filter=tree:0.
|
||||
*/
|
||||
|
||||
// Note: for some reason it is necessary to pass "--progress ---v",
|
||||
// otherwise QProcess returns an error of 128 = 0x80 for the command.
|
||||
|
||||
QString gitCommand("git clone --progress -vvv --filter=blob:none ");
|
||||
gitCommand += m_repositoryPath;
|
||||
Command c(gitCommand);
|
||||
|
||||
qInfo() << "IN CURRENT WD" << m_workingDirectory
|
||||
<< "CLONE" << m_repositoryPath << "...";
|
||||
<< "CLONE VIA COMMAND" << gitCommand;
|
||||
|
||||
if (c.execute(m_workingDirectory)) { // execute the command in wd
|
||||
QString const result = c.getCommandResult();
|
||||
if (!result.isEmpty()) {
|
||||
// Cloning into 'customer_281'...\n
|
||||
static QRegularExpression re("(^\\s*Cloning\\s+into\\s+[']\\s*)(.*)(\\s*['].*$)");
|
||||
QRegularExpressionMatch match = re.match(result);
|
||||
if (match.hasMatch()) {
|
||||
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
|
||||
if (match.captured(2).trimmed() == m_customerNr) {
|
||||
int customer = -1;
|
||||
int cloning = result.indexOf("Cloning", 0, Qt::CaseInsensitive);
|
||||
if (cloning != -1) {
|
||||
customer = result.indexOf("customer_", cloning, Qt::CaseInsensitive);
|
||||
if (customer != -1) {
|
||||
QString customerNr = result.mid(customer);
|
||||
static constexpr char const ch = '\'';
|
||||
int i = customerNr.indexOf(QChar(ch));
|
||||
if (i != -1) {
|
||||
if ((customerNr = customerNr.mid(0, i)) == m_customerNr) {
|
||||
qInfo() << "CLONING" << m_repositoryPath << "OK";
|
||||
return true;
|
||||
}
|
||||
Utils::printCriticalErrorMsg(
|
||||
QString("ERROR CLONE RESULT HAS WRONG CUSTOMER-NR. (%1 != %2) CLONE_RESULT=%3")
|
||||
.arg(customerNr)
|
||||
.arg(m_customerNr)
|
||||
.arg(result));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils::printCriticalErrorMsg(QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=") + result);
|
||||
Utils::printCriticalErrorMsg(
|
||||
QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONING=%1 CUSTOMER=%2 CLONE_RESULT=%3")
|
||||
.arg(cloning)
|
||||
.arg(customer)
|
||||
.arg(result));
|
||||
return false;
|
||||
}
|
||||
Utils::printCriticalErrorMsg("ERROR CLONE RESULT IS EMPTY");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -215,19 +279,34 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool GitClient::gitFsck() {
|
||||
bool r = false;
|
||||
if (QDir(m_customerRepository).exists()) {
|
||||
Command c("git fsck");
|
||||
if ((r = c.execute(m_customerRepository)) == false) {
|
||||
QString const &s = c.getCommandResult().trimmed();
|
||||
Utils::printCriticalErrorMsg(QString("GIT FSCK FAILED: %1").arg(s));
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
/*
|
||||
Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt
|
||||
*/
|
||||
std::optional<QString> GitClient::gitFetch() {
|
||||
std::optional<QString> GitClient::gitPull() {
|
||||
if (QDir(m_customerRepository).exists()) {
|
||||
qInfo() << "BRANCH NAME" << m_branchName;
|
||||
|
||||
Command c("git fetch");
|
||||
Command c("git pull");
|
||||
if (c.execute(m_customerRepository)) {
|
||||
QString const s = c.getCommandResult().trimmed();
|
||||
if (!s.isEmpty()) {
|
||||
QStringList lines = Update::split(s, '\n');
|
||||
worker()->CONSOLE(lines) << Worker::UPDATE_STEP::UPDATE_REPOSITORY;
|
||||
if (!lines.empty()) {
|
||||
static const QRegularExpression alreadyUpToDate("^\\s*Already\\s+up\\s+to\\s+date.*$");
|
||||
if (std::none_of(lines.cbegin(), lines.cend(),
|
||||
[](QString const &s) { return s.contains(alreadyUpToDate); })) {
|
||||
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
|
||||
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
|
||||
// lines can look like this:
|
||||
@ -246,61 +325,42 @@ std::optional<QString> GitClient::gitFetch() {
|
||||
QRegularExpressionMatch match = re.match(lines.at(i));
|
||||
if (match.hasMatch()) {
|
||||
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
|
||||
return match.captured(2);
|
||||
QString const matchCaptured = match.captured(2);
|
||||
worker()->CONSOLE(QStringList(matchCaptured)) << Worker::UPDATE_STEP::UPDATE_REPOSITORY;
|
||||
return matchCaptured;
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
QString("(wrong cap-count (%1)").arg(re.captureCount()));
|
||||
QStringList lst(QString("(wrong capture count (%1)").arg(re.captureCount()));
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
"no regex-match for commits");
|
||||
Utils::printCriticalErrorMsg("NO REGEX MATCH FOR COMMITS");
|
||||
QStringList lst("no regex-match for commits");
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
QString("unkown branch name ") + m_branchName);
|
||||
Utils::printCriticalErrorMsg("UNKNOWN BRANCH NAME " + m_branchName);
|
||||
QStringList lst(QString("unknown branch name ") + m_branchName);
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch",
|
||||
QString("wrong format for result of 'git fetch' ") + s);
|
||||
Utils::printCriticalErrorMsg(QString("WRONG FORMAT FOR RESULT OF 'GIT FETCH' ") + s);
|
||||
return "Already up to date";
|
||||
}
|
||||
} else {
|
||||
// emit m_worker->showErrorMessage("git fetch", "empty result for 'git fetch'");
|
||||
Utils::printInfoMsg("EMPTY RESULT FOR 'GIT FETCH'");
|
||||
QStringList lst(QString("WRONG FORMAT FOR RESULT OF 'GIT PULL' ") + s);
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
} else {
|
||||
QStringList lst("EMPTY RESULT FOR 'GIT PULL'");
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git fetch", QString("repository ") + m_customerRepository + " does not exist");
|
||||
Utils::printCriticalErrorMsg(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST");
|
||||
QStringList lst(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST");
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool GitClient::gitFetchAndDiff() {
|
||||
if (gitFetch()) {
|
||||
QString gitCommand("git diff --compact-summary HEAD..FETCH_HEAD");
|
||||
Command c(gitCommand);
|
||||
return c.execute(m_workingDirectory);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GitClient::gitPull() {
|
||||
if (QDir(m_customerRepository).exists()) {
|
||||
Command c("git pull");
|
||||
if (c.execute(m_customerRepository)) {
|
||||
qInfo() << "PULLED INTO" << m_customerRepository;
|
||||
return true;
|
||||
}
|
||||
Utils::printCriticalErrorMsg(QString("PULL INTO " + m_customerRepository + " FAILED"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<QStringList> GitClient::gitMerge() {
|
||||
Command c("git merge");
|
||||
if (c.execute(m_workingDirectory)) {
|
||||
|
@ -43,12 +43,15 @@ class GitClient : public QObject {
|
||||
|
||||
bool gitCloneAndCheckoutBranch();
|
||||
|
||||
std::optional<QString> gitFetch();
|
||||
bool gitFetchAndDiff();
|
||||
bool gitPull();
|
||||
Worker *worker() { return m_worker; }
|
||||
Worker const *worker() const { return m_worker; }
|
||||
|
||||
std::optional<QString> gitPull();
|
||||
std::optional<QStringList> gitDiff(QString const &commit);
|
||||
std::optional<QStringList> gitMerge();
|
||||
|
||||
bool gitFsck();
|
||||
|
||||
QString gitLastCommit(QString fileName);
|
||||
QStringList gitShowReason(QString branchName);
|
||||
static QString gitBlob(QString fileName);
|
||||
|
@ -56,6 +56,12 @@ void IsmasClient::printDebugMessage(int port,
|
||||
QString const &clientIP,
|
||||
int clientPort,
|
||||
QString const &message) {
|
||||
#if 0
|
||||
Q_UNUSED(port);
|
||||
Q_UNUSED(clientIP);
|
||||
Q_UNUSED(clientPort);
|
||||
Q_UNUSED(message);
|
||||
#else
|
||||
qDebug().noquote()
|
||||
<< "\n"
|
||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||
@ -64,12 +70,19 @@ void IsmasClient::printDebugMessage(int port,
|
||||
<< "local address ..." << clientIP << "\n"
|
||||
<< "local port ......" << clientPort << "\n"
|
||||
<< message;
|
||||
#endif
|
||||
}
|
||||
|
||||
void IsmasClient::printInfoMessage(int port,
|
||||
QString const &clientIP,
|
||||
int clientPort,
|
||||
QString const &message) {
|
||||
#if 0
|
||||
Q_UNUSED(port);
|
||||
Q_UNUSED(clientIP);
|
||||
Q_UNUSED(clientPort);
|
||||
Q_UNUSED(message);
|
||||
#else
|
||||
qInfo().noquote()
|
||||
<< "\n"
|
||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||
@ -78,6 +91,7 @@ void IsmasClient::printInfoMessage(int port,
|
||||
<< "local address ..." << clientIP << "\n"
|
||||
<< "local port ......" << clientPort << "\n"
|
||||
<< message;
|
||||
#endif
|
||||
}
|
||||
|
||||
void IsmasClient::printErrorMessage(int port,
|
||||
@ -301,7 +315,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
}
|
||||
}
|
||||
|
||||
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE RECEIVED ") + buf);
|
||||
// printInfoMessage(port, clientIP, clientPort, QString("MESSAGE RECEIVED ") + buf);
|
||||
QString response(buf);
|
||||
|
||||
if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) {
|
||||
@ -376,16 +390,18 @@ QString IsmasClient::errorBackendNotConnected(QString const &info,
|
||||
version.toStdString().c_str());
|
||||
}
|
||||
|
||||
QString IsmasClient::errorGitClone(int percent, QString const &info, QString const &version) {
|
||||
QString IsmasClient::errorGitClone(QString const &info,
|
||||
QString const &version) {
|
||||
return updateNewsToIsmas("U0003",
|
||||
percent,
|
||||
m_progressInPercent,
|
||||
RESULT_CODE::INSTALL_ERROR,
|
||||
"CLONE CUSTOMER REPOSITORY FAILED",
|
||||
info.toStdString().c_str(),
|
||||
version.toStdString().c_str());
|
||||
}
|
||||
|
||||
QString IsmasClient::backendConnected(QString const &info, QString const &version) {
|
||||
QString IsmasClient::backendConnected(QString const &info,
|
||||
QString const &version) {
|
||||
return updateNewsToIsmas("U0010",
|
||||
m_progressInPercent,
|
||||
RESULT_CODE::SUCCESS,
|
||||
@ -394,7 +410,8 @@ QString IsmasClient::backendConnected(QString const &info, QString const &versio
|
||||
version.toStdString().c_str());
|
||||
}
|
||||
|
||||
QString IsmasClient::execOpkgCommand(QString const &info, QString const &version) {
|
||||
QString IsmasClient::execOpkgCommand(QString const &info,
|
||||
QString const &version) {
|
||||
return updateNewsToIsmas("U0010",
|
||||
m_progressInPercent,
|
||||
RESULT_CODE::SUCCESS,
|
||||
|
@ -177,7 +177,7 @@ public:
|
||||
QString cloneAndCheckoutCustomerRepository(QString const &info, QString const &version = QString()); // clone and checkout customer repository
|
||||
QString checkoutBranch(QString const &info, QString const &version = QString()); // checkout branch
|
||||
QString errorBackendNotConnected(QString const &info, QString const &version = QString()); // checkout branch
|
||||
QString errorGitClone(int percent, QString const &info, QString const &version = QString());
|
||||
QString errorGitClone(QString const &info, QString const &version = QString());
|
||||
QString backendConnected(QString const &info, QString const &version = QString());
|
||||
QString updateTriggerSet(QString const &info, QString const &version = QString());
|
||||
QString errorUpdateTrigger(QString const &info, QString const &version = QString());
|
||||
|
51
main.cpp
51
main.cpp
@ -116,31 +116,63 @@ int main(int argc, char *argv[]) {
|
||||
QCoreApplication::translate("main", "Show extended version (including last git commit)."));
|
||||
parser.addOption(extendedVersionOption);
|
||||
|
||||
QCommandLineOption yoctoVersionOption(QStringList() << "y" << "yocto-version",
|
||||
QCoreApplication::translate("main", "Show yocto version of ATBUpdateTool."));
|
||||
parser.addOption(yoctoVersionOption);
|
||||
|
||||
QCommandLineOption yoctoInstallStatusOption(QStringList() << "Y" << "yocto-install",
|
||||
QCoreApplication::translate("main", "Show yocto install status of ATBUpdateTool."));
|
||||
parser.addOption(yoctoInstallStatusOption);
|
||||
|
||||
// Process the actual command line arguments given by the user
|
||||
parser.process(a);
|
||||
QString plugInDir = parser.value(pluginDirectoryOption);
|
||||
QString plugInName = parser.value(pluginNameOption);
|
||||
QString workingDir = parser.value(workingDirectoryOption);
|
||||
bool const dryRun = parser.isSet(dryRunOption);
|
||||
bool const showYoctoVersion = parser.isSet(yoctoVersionOption);
|
||||
bool const showYoctoInstallStatus = parser.isSet(yoctoInstallStatusOption);
|
||||
bool const showExtendedVersion = parser.isSet(extendedVersionOption);
|
||||
QString const rtPath = QCoreApplication::applicationDirPath();
|
||||
|
||||
int machineNr = Utils::read1stLineOfFile("/etc/machine_nr");
|
||||
int customerNr = Utils::read1stLineOfFile("/etc/cust_nr");
|
||||
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr");
|
||||
QString const branchName = (zoneNr != 0)
|
||||
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
||||
|
||||
QThread::currentThread()->setObjectName("main thread");
|
||||
qInfo() << "Main thread" << QThread::currentThreadId();
|
||||
|
||||
if (showExtendedVersion) {
|
||||
printf(APP_EXTENDED_VERSION"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (showYoctoVersion) {
|
||||
printf("%s\n", Worker::getATBUpdateToolYoctoVersion().toStdString().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (showYoctoInstallStatus) {
|
||||
printf("%s\n", Worker::getATBUpdateToolYoctoInstallationStatus().toStdString().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!QDir(plugInDir).exists()) {
|
||||
qCritical() << plugInDir
|
||||
<< "does not exists, but has to contain dc-library";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
qInfo() << "pwd ..............." << rtPath;
|
||||
qInfo() << "plugInDir ........." << plugInDir;
|
||||
qInfo() << "plugInName ........" << plugInName;
|
||||
qInfo() << "workingDir ........" << workingDir;
|
||||
qInfo() << "dryRun ............" << dryRun;
|
||||
qInfo() << "pwd ......................" << rtPath;
|
||||
qInfo() << "plugInDir ................" << plugInDir;
|
||||
qInfo() << "plugInName ..............." << plugInName;
|
||||
qInfo() << "workingDir ..............." << workingDir;
|
||||
qInfo() << "dryRun ..................." << dryRun;
|
||||
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
|
||||
//qInfo() << "yocto-version ............" << Worker::getATBUpdateToolYoctoVersion();
|
||||
//qInfo() << "yocto-install-status ....." << Worker::getATBUpdateToolYoctoInstallationStatus();
|
||||
|
||||
// before loading the library, delete all possible shared memory segments
|
||||
#if defined Q_OS_LINUX || defined Q_OS_UNIX
|
||||
@ -153,15 +185,6 @@ int main(int argc, char *argv[]) {
|
||||
hw->dc_autoRequest(true);
|
||||
// hw->dc_openSerial(5, "115200", "ttymxc2", 1);
|
||||
|
||||
int machineNr = Utils::read1stLineOfFile("/etc/machine_nr");
|
||||
int customerNr = Utils::read1stLineOfFile("/etc/cust_nr");
|
||||
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr");
|
||||
QString const branchName = (zoneNr != 0)
|
||||
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
||||
|
||||
QThread::currentThread()->setObjectName("main thread");
|
||||
qInfo() << "Main thread" << QThread::currentThreadId();
|
||||
|
||||
Worker worker(customerNr,
|
||||
machineNr,
|
||||
zoneNr,
|
||||
|
@ -96,7 +96,7 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren
|
||||
, m_worker(worker)
|
||||
, m_width(70)
|
||||
, m_progressRunning(false)
|
||||
, m_progressValue(0)
|
||||
// , m_progressValue(0)
|
||||
, m_update(update)
|
||||
, m_updateStep(UpdateDcEvent::UpdateStep::NONE) {
|
||||
|
||||
@ -155,6 +155,8 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren
|
||||
connect(m_worker, SIGNAL(appendText(QString,QString)),this,SLOT(onAppendText(QString,QString)));
|
||||
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)),this, SLOT(onShowErrorMessage(QString,QString)));
|
||||
connect(m_worker, SIGNAL(showStatusMessage(QString,QString)),this, SLOT(onShowStatusMessage(QString,QString)));
|
||||
connect(m_worker, SIGNAL(showErrorMessage(QStringList)),this, SLOT(onShowErrorMessage(QStringList)));
|
||||
connect(m_worker, SIGNAL(showStatusMessage(QString,QString)),this, SLOT(onShowStatusMessage(QString,QString)));
|
||||
connect(m_worker, SIGNAL(replaceLast(QString,QString)),this,SLOT(onReplaceLast(QString,QString)));
|
||||
connect(m_worker, SIGNAL(replaceLast(QStringList,QString)),this, SLOT(onReplaceLast(QStringList,QString)));
|
||||
}
|
||||
@ -178,22 +180,22 @@ void MainWindow::customEvent(QEvent *event) {
|
||||
case START_PROGRESS_LOOP: {
|
||||
m_progressRunning = true;
|
||||
ui->updateProgress->reset();
|
||||
m_progressValue = 10;
|
||||
QApplication::postEvent(this, new ProgressEvent(this, m_progressValue));
|
||||
// m_progressValue = 10;
|
||||
QApplication::postEvent(this, new ProgressEvent(this, 1));
|
||||
} break;
|
||||
case STOP_PROGRESS_LOOP: {
|
||||
m_progressRunning = false;
|
||||
m_progressValue -= 10;
|
||||
m_worker->setProgress(m_progressValue/10);
|
||||
// m_progressValue -= 10;
|
||||
// m_worker->setProgress(m_progressValue/10);
|
||||
} break;
|
||||
default: {
|
||||
if (m_progressRunning) {
|
||||
m_progressValue = progress;
|
||||
ui->updateProgress->setValue(progress/10);
|
||||
QApplication::postEvent(this, new ProgressEvent(this, progress+10));
|
||||
QThread::msleep(500);
|
||||
}
|
||||
}
|
||||
// m_progressValue = progress;
|
||||
ui->updateProgress->setValue(progress);
|
||||
// ueberpruefen: hauptfenster schickt sich selber ein event
|
||||
// QApplication::postEvent(this, new ProgressEvent(this, progress));
|
||||
// QThread::msleep(500);
|
||||
}}
|
||||
}
|
||||
} else
|
||||
if (sender == m_worker) {
|
||||
@ -327,8 +329,18 @@ void MainWindow::onRestartExitTimer() {
|
||||
|
||||
void MainWindow::onQuit() {
|
||||
m_exitTimer->stop();
|
||||
qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode());
|
||||
qApp->exit(m_worker->returnCode());
|
||||
int errorCode = 0;
|
||||
|
||||
qCritical()
|
||||
<< QString("ON QUIT: CURRENT STEP %1")
|
||||
.arg(m_worker->getSmap()[m_worker->currentStep()]);
|
||||
|
||||
// TODO: replace SEND_LAST_VERSION with UPDATE_SUCCEEDED
|
||||
if (m_worker->currentStep() != Worker::UPDATE_STEP::SEND_LAST_VERSION) {
|
||||
errorCode = -1;
|
||||
}
|
||||
qCritical() << QString("ON QUIT: EXIT CODE %1").arg(errorCode);
|
||||
qApp->exit(errorCode);
|
||||
}
|
||||
|
||||
void MainWindow::scrollDownTextEdit() {
|
||||
@ -448,3 +460,21 @@ void MainWindow::onShowErrorMessage(QString title, QString text) {
|
||||
void MainWindow::onShowStatusMessage(QString title, QString text) {
|
||||
onShowMessage(title, text);
|
||||
}
|
||||
|
||||
void MainWindow::onShowErrorMessage(QStringList lst) {
|
||||
if (lst.size() >= 2) {
|
||||
onShowMessage(lst.at(0), lst.at(1));
|
||||
}
|
||||
if (lst.size() == 1) {
|
||||
onShowMessage(lst.at(0), "");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onShowStatusMessage(QStringList lst) {
|
||||
if (lst.size() >= 2) {
|
||||
onShowMessage(lst.at(0), lst.at(1));
|
||||
}
|
||||
if (lst.size() == 1) {
|
||||
onShowMessage(lst.at(0), "");
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
static const int BL_IS_UP_COUNT = 5;
|
||||
static const int BL_STOP_COUNT = 5;
|
||||
|
||||
int progressValue() const { return m_progressValue; }
|
||||
// int progressValue() const { return m_progressValue; }
|
||||
hwinf *getPlugin() { return m_hw; }
|
||||
hwinf const *getPlugin() const { return m_hw; }
|
||||
Update *getUpdate() { return m_update; }
|
||||
@ -48,6 +48,8 @@ public slots:
|
||||
void onReplaceLast(QString, QString suffix = "");
|
||||
void onShowErrorMessage(QString, QString);
|
||||
void onShowStatusMessage(QString, QString);
|
||||
void onShowErrorMessage(QStringList);
|
||||
void onShowStatusMessage(QStringList);
|
||||
void onStopStartTimer();
|
||||
void onRestartExitTimer();
|
||||
void onEnableExit();
|
||||
@ -76,7 +78,7 @@ private:
|
||||
QTimer *m_startTimer;
|
||||
QTimer *m_exitTimer;
|
||||
bool m_progressRunning;
|
||||
int m_progressValue;
|
||||
//int m_progressValue;
|
||||
Update *m_update;
|
||||
UpdateDcEvent::UpdateStep m_updateStep;
|
||||
};
|
||||
|
@ -846,8 +846,8 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
|
||||
res = false;
|
||||
}
|
||||
m_worker->stopProgressLoop();
|
||||
m_worker->setProgress(100);
|
||||
// m_worker->stopProgressLoop();
|
||||
// m_worker->setProgress(100);
|
||||
|
||||
if (res == false) {
|
||||
break;
|
||||
|
67
utils.cpp
67
utils.cpp
@ -46,17 +46,70 @@ QString Utils::zoneName(quint8 i) {
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
void Utils::printCriticalErrorMsg(QString const &errorMsg) {
|
||||
qCritical() << QString(80, '!');
|
||||
void Utils::printCriticalErrorMsg(QString const &errorMsg, bool upper, bool lower) {
|
||||
if (upper) qCritical() << QString(80, 'E');
|
||||
|
||||
qCritical() << errorMsg;
|
||||
qCritical() << QString(80, '!');
|
||||
|
||||
if (lower) qCritical() << QString(80, 'E');
|
||||
}
|
||||
|
||||
void Utils::printInfoMsg(QString const &infoMsg) {
|
||||
qCritical() << QString(80, '=');
|
||||
qCritical() << infoMsg;
|
||||
qCritical() << QString(80, '=');
|
||||
void Utils::printCriticalErrorMsg(QStringList const &errorMsg) {
|
||||
qCritical() << QString(80, 'E');
|
||||
for (int i = 0; i < errorMsg.size(); ++i) {
|
||||
qCritical() << errorMsg.at(i);
|
||||
}
|
||||
qCritical() << QString(80, 'E');
|
||||
}
|
||||
|
||||
void Utils::printUpdateStatusMsg(QDebug &debug, QStringList const &updateMsg) {
|
||||
debug << QString(80, 'U');
|
||||
for (int i = 0; i < updateMsg.size(); ++i) {
|
||||
debug << updateMsg.at(i);
|
||||
}
|
||||
debug << QString(80, 'U');
|
||||
}
|
||||
|
||||
void Utils::printUpdateStatusMsg(QStringList const &updateMsg) {
|
||||
qCritical() << QString(80, 'U');
|
||||
for (int i = 0; i < updateMsg.size(); ++i) {
|
||||
qCritical() << updateMsg.at(i);
|
||||
}
|
||||
qCritical() << QString(80, 'U');
|
||||
}
|
||||
|
||||
void Utils::printUpdateStatusMsg(QString const &updateMsg, bool upper, bool lower) {
|
||||
if (upper) qCritical() << QString(80, 'U');
|
||||
|
||||
qCritical() << updateMsg;
|
||||
|
||||
if (lower) qCritical() << QString(80, 'U');
|
||||
}
|
||||
|
||||
void Utils::printUpdateStatusMsg(QDebug &debug, QString const &updateMsg,
|
||||
bool upper, bool lower) {
|
||||
if (upper) debug << QString(80, 'U');
|
||||
|
||||
debug << updateMsg;
|
||||
|
||||
if (lower) debug << QString(80, 'U');
|
||||
|
||||
}
|
||||
|
||||
void Utils::printInfoMsg(QString const &infoMsg, bool upper, bool lower) {
|
||||
if (upper) qCritical() << QString(80, 'I');
|
||||
|
||||
qCritical() << infoMsg;
|
||||
|
||||
if (lower) qCritical() << QString(80, 'I');
|
||||
}
|
||||
|
||||
void Utils::printInfoMsg(QStringList const &infoMsg) {
|
||||
qCritical() << QString(80, 'I');
|
||||
for (int i = 0; i < infoMsg.size(); ++i) {
|
||||
qCritical() << infoMsg.at(i);
|
||||
}
|
||||
qCritical() << QString(80, 'I');
|
||||
}
|
||||
|
||||
void Utils::printLineEditInfo(QStringList const &lines) {
|
||||
|
11
utils.h
11
utils.h
@ -8,12 +8,19 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Utils {
|
||||
int read1stLineOfFile(QString fileName);
|
||||
QString zoneName(quint8 i);
|
||||
void printCriticalErrorMsg(QString const &errorMsg);
|
||||
void printInfoMsg(QString const &infoMsg);
|
||||
void printCriticalErrorMsg(QString const &errorMsg, bool upper=false, bool lower=false);
|
||||
void printCriticalErrorMsg(QStringList const &errorMsg);
|
||||
void printInfoMsg(QString const &infoMsg, bool upper=false, bool lower=false);
|
||||
void printInfoMsg(QStringList const &infoMsg);
|
||||
void printUpdateStatusMsg(QDebug &debug, QStringList const &updateMsg);
|
||||
void printUpdateStatusMsg(QStringList const &updateMsg);
|
||||
void printUpdateStatusMsg(QString const &updateMsg, bool upper=false, bool lower=false);
|
||||
void printUpdateStatusMsg(QDebug &debug, QString const &updateMsg, bool upper=false, bool lower=false);
|
||||
void printLineEditInfo(QStringList const &lines);
|
||||
QString getTariffLoadTime(QString fileName);
|
||||
QString rstrip(QString const &str);
|
||||
|
1440
worker.cpp
1440
worker.cpp
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user