Compare commits

...

47 Commits

Author SHA1 Message Date
4b3a39b0e6 Set version to 1.3.14.
Add compile flag -C (so it is possible to use /*fall through*/ without
having the proprocessor to remove this comment.
2023-10-30 15:35:38 +01:00
a44b780d93 Minor: Add header for using RAII in sending SEND-LAST-VERSION to ISAMS. 2023-10-30 15:29:23 +01:00
19dfae9b56 Use output functions ISMAS(), GUI() and CONSOLE(), which point to friend
operators<< in Worker-class.
2023-10-30 15:28:25 +01:00
bef0d4fe12 Refactor the update process: streamline code. When WAIT button is not
active, the a clone or a fix of a defunct repository is possible, but
not more.
If WAIT button is active, the at least the opkg_commnds are executed. If
there are chenged files, they are handkled as wll.
2023-10-30 15:25:49 +01:00
72a2fc781c Minor: reove obsolete m_returnCode. 2023-10-30 15:24:33 +01:00
fc264689b1 Use and implement getAPISMYoctoVersion() and
getAPISMYoctoInstallationSTatus().
2023-10-30 15:22:59 +01:00
fc587456d5 Filling the QMap Worker:smap with data. 2023-10-30 15:21:26 +01:00
a2b933ab71 Minor: Added UPDATE_STEP_WRONG. 2023-10-30 15:20:15 +01:00
7d0fdf4d6d Small fixes:
1: fixed wrong parameters of a connect().
2: Minor: improved onQuit().
2023-10-30 15:17:59 +01:00
c2ce44c79b Adding three friend operator<< functions to output status information of
the update process: the first on outputs to CONSOLE(), the second one
outputs to ISMAS() and the last one to GUI(), i.e. the text edit of the
main window.
2023-10-30 15:15:30 +01:00
16a9556863 bool customerEnvironment();
bool filesToUpdate();
bool updateFiles();
bool syncCustomerRepositoryAndFS();
bool saveLogFile(): remove progress parameter.
2023-10-30 15:14:19 +01:00
48896f97ec Adding UPDATE_STEP_WRONG: helper variable to be used in text edit of
main window.
2023-10-30 15:13:04 +01:00
4486317cb2 dd declaration for getAPISMYoctoVersion() and
getAPISMYoctoInstallationStatus(): the first one returning the
yocto-version
of APIS, the second returning the installation status of APIS as display
in 'opkg info'.
2023-10-30 15:11:06 +01:00
6b9b88ea19 Adding member variables to check if customer repository was a fresh
clone, or if it was already existent.
2023-10-30 15:09:33 +01:00
99a99d95a1 Adding UPDATE_STEP enum plus associated interger defines.
Adding QMap: Worker::smap, which contains names of UPDATE_STEP-members.
2023-10-30 15:07:28 +01:00
d4ddbbee21 Add class UpdateProcessRunning: use for sending SEND-LAST-VERSION as
part of its destruktor: RAII-pattern.
2023-10-30 15:05:30 +01:00
34e5189945 comment out some debug output -> too much output. 2023-10-30 15:03:35 +01:00
c44c805238 Use some special output methods using ISMAS(), GUI() nad CONSOLE(). 2023-10-30 15:00:57 +01:00
196f1a730e gitPull(): don't use regex anumore, but just plain
string-matching/searching.
Regex seems to be quite error-prone.
2023-10-30 14:59:58 +01:00
7dc04c4422 Add helper function worker(), returning the worker-object. 2023-10-30 14:56:19 +01:00
5efac2619b sicherung der aenderungen 2023-10-23 16:16:11 +02:00
9b0f741b9b to be continued on monday 2023-10-22 19:44:45 +02:00
81c5f8ee7e Save for the weekend. 2023-10-20 13:55:18 +02:00
29e6a25e72 Add comment for version 1.3.13 2023-10-19 13:45:52 +02:00
5abc057bda Minor: add possible debug messages. 2023-10-19 13:44:51 +02:00
8aeb7ecfea Don't check opkg_commands-file in the system-filesystem to remove
confusing error-messages.
2023-10-19 13:43:53 +02:00
4bb8e241b6 Update process: check sanity of customer repository: are etc/ and
opt/directories contained? If not, remove the repository and clone it
again. This is done without checking the ISMAS-WAIT-button.
2023-10-19 13:41:44 +02:00
4469a23f9c Implemented helpers:
bool isRepositoryCorrupted();
    bool repairCorruptedRepository();

    int sendCloneAndCheckoutSuccess();
    int sendCloneAndCheckoutFailure();
    int sendIsmasTriggerFailure();
2023-10-19 13:39:48 +02:00
d1f795e2db Added helpers:
bool isRepositoryCorrupted();
    bool repairCorruptedRepository();

    int sendCloneAndCheckoutSuccess();
    int sendCloneAndCheckoutFailure();
    int sendIsmasTriggerFailure();

and static variables

    static constexpr const int CLONE_AND_CHECKOUT_SUCCESS = 0;
    static constexpr const int CLONE_AND_CHECKOUT_FAILURE = -3;
    static constexpr const int ISMAS_TRIGGER_FAILURE = -5;
2023-10-19 13:38:16 +02:00
6865056f4b Replace regex in gitCloneCustomerRepository() with straight-forward
steing-handling: regex sometimes returned error.
2023-10-19 13:35:07 +02:00
37bd5c90d3 Add printUpdateStatus() helper for QString 2023-10-19 13:34:07 +02:00
fcba120dfa Minor: commented out unnecessary debug/info output 2023-10-18 16:21:44 +02:00
1d4f50fb9f Add printing-utils that also take string-lists 2023-10-18 16:20:49 +02:00
a78040a037 Minor: add error-debug-message in ase customer-nr is wrong 2023-10-18 16:19:37 +02:00
9b175d7789 Set version to 1.3.12 2023-10-18 11:45:54 +02:00
2d7f145a25 Replaced using gitFetch() with gitPull() 2023-10-18 11:40:04 +02:00
4589c4ca76 Removed gitFetchAndDiff() and original version of gitPull(). 2023-10-18 11:38:26 +02:00
a32258a59e Replaced "git fetch" with "git pull". 2023-10-18 11:37:46 +02:00
22f25e5251 Replaced 'git clone' with 'git clone --filter=blob:none' to speed
up cloning of customer-repository.
2023-10-18 11:36:13 +02:00
258d883a51 Replaced gitFetch() with gitPull() 2023-10-18 11:35:23 +02:00
504e242d42 Implemented getATBUpdateToolYoctoVersion() and getATBUpdateToolYoctoInstallationStatus() 2023-10-18 11:31:15 +02:00
731cdcbe09 Added getATBUpdateToolYoctoVersion() and getATBUpdateToolYoctoInstallationStatus() 2023-10-18 11:30:12 +02:00
b4e2d4c54a Minor: Move reading of machine_nr, customer_nr and zone_nr upwards. 2023-10-18 11:28:06 +02:00
42961dea40 Add command-parameters yoctoVersionOption (yocto-version of
ATBUpdateTool as reported by opkg), and yoctoInstallStatusOption (info
if ATBUpdateTool is installed as reported by opkg).
2023-10-18 11:26:30 +02:00
fd2f601f67 Add printAupdateStatusMsg(). 2023-10-18 11:21:32 +02:00
b45af505cd Minor: change output format. 2023-10-18 11:21:08 +02:00
2dfe80b654 Add printUpdateStatusMsg() 2023-10-18 11:20:31 +02:00
13 changed files with 2063 additions and 1015 deletions

View File

@ -35,6 +35,42 @@ DEFINES += QT_DEPRECATED_WARNINGS
# Fix display of UPDATE_SUCCESS when opkg_command fails. Detected when # Fix display of UPDATE_SUCCESS when opkg_command fails. Detected when
# updating apsim failed. # updating apsim failed.
# 1.3.11: Integrate version of ATBUpdateTool in SendLastVersion-ISMAS-message. # 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 { win32 {
BUILD_DATE=$$system("date /t") BUILD_DATE=$$system("date /t")
@ -46,7 +82,6 @@ win32 {
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1") GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
VERSION="1.3.11"
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}" EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
INCLUDEPATH += plugins INCLUDEPATH += plugins
@ -59,6 +94,8 @@ DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\" DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\" DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
# keep comments, as /* fall through */
QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -g QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy QMAKE_CXXFLAGS += -Wno-deprecated-copy
@ -67,14 +104,14 @@ contains( CONFIG, PTU5 ) {
CONFIG += link_pkgconfig CONFIG += link_pkgconfig
lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport
QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7 QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7
QMAKE_CXXFLAGS += -Wno-deprecated-copy # QMAKE_CXXFLAGS += -Wno-deprecated-copy
ARCH = PTU5 ARCH = PTU5
DEFINES+=PTU5 DEFINES+=PTU5
} }
contains( CONFIG, PTU5_YOCTO ) { contains( CONFIG, PTU5_YOCTO ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7 QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7
QMAKE_CXXFLAGS += -Wno-deprecated-copy # QMAKE_CXXFLAGS += -Wno-deprecated-copy
PTU5BASEPATH = /opt/devel/ptu5 PTU5BASEPATH = /opt/devel/ptu5
ARCH = PTU5 ARCH = PTU5
DEFINES+=PTU5 DEFINES+=PTU5
@ -88,7 +125,7 @@ contains( CONFIG, DesktopLinux ) {
# QMAKE_CC = ccache $$QMAKE_CC # QMAKE_CC = ccache $$QMAKE_CC
# QMAKE_CXX = ccache $$QMAKE_CXX # QMAKE_CXX = ccache $$QMAKE_CXX
QMAKE_CXXFLAGS += -std=c++17 QMAKE_CXXFLAGS += -std=c++17
QMAKE_CXXFLAGS += -Wno-deprecated-copy # QMAKE_CXXFLAGS += -Wno-deprecated-copy
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments } linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
ARCH = DesktopLinux ARCH = DesktopLinux
DEFINES+=DesktopLinux DEFINES+=DesktopLinux

View File

@ -26,29 +26,93 @@ GitClient::GitClient(QString const &customerNrStr,
} }
bool GitClient::gitCloneCustomerRepository() { 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; gitCommand += m_repositoryPath;
Command c(gitCommand); Command c(gitCommand);
qInfo() << "IN CURRENT WD" << m_workingDirectory qInfo() << "IN CURRENT WD" << m_workingDirectory
<< "CLONE" << m_repositoryPath << "..."; << "CLONE VIA COMMAND" << gitCommand;
if (c.execute(m_workingDirectory)) { // execute the command in wd if (c.execute(m_workingDirectory)) { // execute the command in wd
QString const result = c.getCommandResult(); QString const result = c.getCommandResult();
if (!result.isEmpty()) { if (!result.isEmpty()) {
// Cloning into 'customer_281'...\n // Cloning into 'customer_281'...\n
static QRegularExpression re("(^\\s*Cloning\\s+into\\s+[']\\s*)(.*)(\\s*['].*$)"); int customer = -1;
QRegularExpressionMatch match = re.match(result); int cloning = result.indexOf("Cloning", 0, Qt::CaseInsensitive);
if (match.hasMatch()) { if (cloning != -1) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches customer = result.indexOf("customer_", cloning, Qt::CaseInsensitive);
if (match.captured(2).trimmed() == m_customerNr) { if (customer != -1) {
qInfo() << "CLONING" << m_repositoryPath << "OK"; QString customerNr = result.mid(customer);
return true; 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. CLONING=%1 CUSTOMER=%2 CLONE_RESULT=%3")
.arg(cloning)
.arg(customer)
.arg(result));
return false;
} }
Utils::printCriticalErrorMsg(QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=") + result); Utils::printCriticalErrorMsg("ERROR CLONE RESULT IS EMPTY");
} }
return false; return false;
} }
@ -215,92 +279,88 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
return std::nullopt; 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 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()) { if (QDir(m_customerRepository).exists()) {
qInfo() << "BRANCH NAME" << m_branchName; qInfo() << "BRANCH NAME" << m_branchName;
Command c("git fetch"); Command c("git pull");
if (c.execute(m_customerRepository)) { if (c.execute(m_customerRepository)) {
QString const s = c.getCommandResult().trimmed(); QString const s = c.getCommandResult().trimmed();
if (!s.isEmpty()) { if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n'); QStringList lines = Update::split(s, '\n');
worker()->CONSOLE(lines) << Worker::UPDATE_STEP::UPDATE_REPOSITORY;
if (!lines.empty()) { if (!lines.empty()) {
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr"); static const QRegularExpression alreadyUpToDate("^\\s*Already\\s+up\\s+to\\s+date.*$");
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master"; if (std::none_of(lines.cbegin(), lines.cend(),
// lines can look like this: [](QString const &s) { return s.contains(alreadyUpToDate); })) {
// From https://git.mimbach49.de/GerhardHoffmann/customer_281 int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
// 41ec581..5d25ac3 master -> origin/master m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1 // lines can look like this:
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2 // From https://git.mimbach49.de/GerhardHoffmann/customer_281
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3 // 41ec581..5d25ac3 master -> origin/master
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5 // ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
bool found = false; // 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
for (int i=0; i < lines.size(); ++i) { // 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
if (lines.at(i).contains(m_branchName)) { // 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
found = true; bool found = false;
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 for (int i=0; i < lines.size(); ++i) {
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); if (lines.at(i).contains(m_branchName)) {
QRegularExpressionMatch match = re.match(lines.at(i)); found = true;
if (match.hasMatch()) { // 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
return match.captured(2); QRegularExpressionMatch match = re.match(lines.at(i));
if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
QString const matchCaptured = match.captured(2);
worker()->CONSOLE(QStringList(matchCaptured)) << Worker::UPDATE_STEP::UPDATE_REPOSITORY;
return matchCaptured;
} else {
QStringList lst(QString("(wrong capture count (%1)").arg(re.captureCount()));
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
}
} else { } else {
emit m_worker->showErrorMessage("git fetch", QStringList lst("no regex-match for commits");
QString("(wrong cap-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");
} }
} }
} if (!found) {
if (!found) { QStringList lst(QString("unknown branch name ") + m_branchName);
emit m_worker->showErrorMessage("git fetch", worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
QString("unkown branch name ") + m_branchName); }
Utils::printCriticalErrorMsg("UNKNOWN BRANCH NAME " + m_branchName); } else {
return "Already up to date";
} }
} else { } else {
emit m_worker->showErrorMessage("git fetch", QStringList lst(QString("WRONG FORMAT FOR RESULT OF 'GIT PULL' ") + s);
QString("wrong format for result of 'git fetch' ") + s); worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
Utils::printCriticalErrorMsg(QString("WRONG FORMAT FOR RESULT OF 'GIT FETCH' ") + s);
} }
} else { } else {
// emit m_worker->showErrorMessage("git fetch", "empty result for 'git fetch'"); QStringList lst("EMPTY RESULT FOR 'GIT PULL'");
Utils::printInfoMsg("EMPTY RESULT FOR 'GIT FETCH'"); worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
} }
} }
} else { } else {
emit m_worker->showErrorMessage("git fetch", QString("repository ") + m_customerRepository + " does not exist"); QStringList lst(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST");
Utils::printCriticalErrorMsg(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST"); worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
} }
return std::nullopt; 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() { std::optional<QStringList> GitClient::gitMerge() {
Command c("git merge"); Command c("git merge");
if (c.execute(m_workingDirectory)) { if (c.execute(m_workingDirectory)) {

View File

@ -43,12 +43,15 @@ class GitClient : public QObject {
bool gitCloneAndCheckoutBranch(); bool gitCloneAndCheckoutBranch();
std::optional<QString> gitFetch(); Worker *worker() { return m_worker; }
bool gitFetchAndDiff(); Worker const *worker() const { return m_worker; }
bool gitPull();
std::optional<QString> gitPull();
std::optional<QStringList> gitDiff(QString const &commit); std::optional<QStringList> gitDiff(QString const &commit);
std::optional<QStringList> gitMerge(); std::optional<QStringList> gitMerge();
bool gitFsck();
QString gitLastCommit(QString fileName); QString gitLastCommit(QString fileName);
QStringList gitShowReason(QString branchName); QStringList gitShowReason(QString branchName);
static QString gitBlob(QString fileName); static QString gitBlob(QString fileName);

View File

@ -56,6 +56,12 @@ void IsmasClient::printDebugMessage(int port,
QString const &clientIP, QString const &clientIP,
int clientPort, int clientPort,
QString const &message) { QString const &message) {
#if 0
Q_UNUSED(port);
Q_UNUSED(clientIP);
Q_UNUSED(clientPort);
Q_UNUSED(message);
#else
qDebug().noquote() qDebug().noquote()
<< "\n" << "\n"
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
@ -64,12 +70,19 @@ void IsmasClient::printDebugMessage(int port,
<< "local address ..." << clientIP << "\n" << "local address ..." << clientIP << "\n"
<< "local port ......" << clientPort << "\n" << "local port ......" << clientPort << "\n"
<< message; << message;
#endif
} }
void IsmasClient::printInfoMessage(int port, void IsmasClient::printInfoMessage(int port,
QString const &clientIP, QString const &clientIP,
int clientPort, int clientPort,
QString const &message) { QString const &message) {
#if 0
Q_UNUSED(port);
Q_UNUSED(clientIP);
Q_UNUSED(clientPort);
Q_UNUSED(message);
#else
qInfo().noquote() qInfo().noquote()
<< "\n" << "\n"
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
@ -78,6 +91,7 @@ void IsmasClient::printInfoMessage(int port,
<< "local address ..." << clientIP << "\n" << "local address ..." << clientIP << "\n"
<< "local port ......" << clientPort << "\n" << "local port ......" << clientPort << "\n"
<< message; << message;
#endif
} }
void IsmasClient::printErrorMessage(int port, 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); QString response(buf);
if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) { if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) {
@ -376,16 +390,18 @@ QString IsmasClient::errorBackendNotConnected(QString const &info,
version.toStdString().c_str()); 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", return updateNewsToIsmas("U0003",
percent, m_progressInPercent,
RESULT_CODE::INSTALL_ERROR, RESULT_CODE::INSTALL_ERROR,
"CLONE CUSTOMER REPOSITORY FAILED", "CLONE CUSTOMER REPOSITORY FAILED",
info.toStdString().c_str(), info.toStdString().c_str(),
version.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", return updateNewsToIsmas("U0010",
m_progressInPercent, m_progressInPercent,
RESULT_CODE::SUCCESS, RESULT_CODE::SUCCESS,
@ -394,7 +410,8 @@ QString IsmasClient::backendConnected(QString const &info, QString const &versio
version.toStdString().c_str()); 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", return updateNewsToIsmas("U0010",
m_progressInPercent, m_progressInPercent,
RESULT_CODE::SUCCESS, RESULT_CODE::SUCCESS,

View File

@ -177,7 +177,7 @@ public:
QString cloneAndCheckoutCustomerRepository(QString const &info, QString const &version = QString()); // clone and checkout customer repository 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 checkoutBranch(QString const &info, QString const &version = QString()); // checkout branch
QString errorBackendNotConnected(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 backendConnected(QString const &info, QString const &version = QString());
QString updateTriggerSet(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()); QString errorUpdateTrigger(QString const &info, QString const &version = QString());

View File

@ -116,31 +116,63 @@ int main(int argc, char *argv[]) {
QCoreApplication::translate("main", "Show extended version (including last git commit).")); QCoreApplication::translate("main", "Show extended version (including last git commit)."));
parser.addOption(extendedVersionOption); 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 // Process the actual command line arguments given by the user
parser.process(a); parser.process(a);
QString plugInDir = parser.value(pluginDirectoryOption); QString plugInDir = parser.value(pluginDirectoryOption);
QString plugInName = parser.value(pluginNameOption); QString plugInName = parser.value(pluginNameOption);
QString workingDir = parser.value(workingDirectoryOption); QString workingDir = parser.value(workingDirectoryOption);
bool const dryRun = parser.isSet(dryRunOption); bool const dryRun = parser.isSet(dryRunOption);
bool const showYoctoVersion = parser.isSet(yoctoVersionOption);
bool const showYoctoInstallStatus = parser.isSet(yoctoInstallStatusOption);
bool const showExtendedVersion = parser.isSet(extendedVersionOption); bool const showExtendedVersion = parser.isSet(extendedVersionOption);
QString const rtPath = QCoreApplication::applicationDirPath(); 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) { if (showExtendedVersion) {
printf(APP_EXTENDED_VERSION"\n"); printf(APP_EXTENDED_VERSION"\n");
return 0; 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()) { if (!QDir(plugInDir).exists()) {
qCritical() << plugInDir qCritical() << plugInDir
<< "does not exists, but has to contain dc-library"; << "does not exists, but has to contain dc-library";
exit(-1); exit(-1);
} }
qInfo() << "pwd ..............." << rtPath; qInfo() << "pwd ......................" << rtPath;
qInfo() << "plugInDir ........." << plugInDir; qInfo() << "plugInDir ................" << plugInDir;
qInfo() << "plugInName ........" << plugInName; qInfo() << "plugInName ..............." << plugInName;
qInfo() << "workingDir ........" << workingDir; qInfo() << "workingDir ..............." << workingDir;
qInfo() << "dryRun ............" << dryRun; 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 // before loading the library, delete all possible shared memory segments
#if defined Q_OS_LINUX || defined Q_OS_UNIX #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_autoRequest(true);
// hw->dc_openSerial(5, "115200", "ttymxc2", 1); // 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, Worker worker(customerNr,
machineNr, machineNr,
zoneNr, zoneNr,

View File

@ -96,7 +96,7 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren
, m_worker(worker) , m_worker(worker)
, m_width(70) , m_width(70)
, m_progressRunning(false) , m_progressRunning(false)
, m_progressValue(0) // , m_progressValue(0)
, m_update(update) , m_update(update)
, m_updateStep(UpdateDcEvent::UpdateStep::NONE) { , 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(appendText(QString,QString)),this,SLOT(onAppendText(QString,QString)));
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)),this, SLOT(onShowErrorMessage(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(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(QString,QString)),this,SLOT(onReplaceLast(QString,QString)));
connect(m_worker, SIGNAL(replaceLast(QStringList,QString)),this, SLOT(onReplaceLast(QStringList,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: { case START_PROGRESS_LOOP: {
m_progressRunning = true; m_progressRunning = true;
ui->updateProgress->reset(); ui->updateProgress->reset();
m_progressValue = 10; // m_progressValue = 10;
QApplication::postEvent(this, new ProgressEvent(this, m_progressValue)); QApplication::postEvent(this, new ProgressEvent(this, 1));
} break; } break;
case STOP_PROGRESS_LOOP: { case STOP_PROGRESS_LOOP: {
m_progressRunning = false; m_progressRunning = false;
m_progressValue -= 10; // m_progressValue -= 10;
m_worker->setProgress(m_progressValue/10); // m_worker->setProgress(m_progressValue/10);
} break; } break;
default: { default: {
if (m_progressRunning) { if (m_progressRunning) {
m_progressValue = progress; // m_progressValue = progress;
ui->updateProgress->setValue(progress/10); ui->updateProgress->setValue(progress);
QApplication::postEvent(this, new ProgressEvent(this, progress+10)); // ueberpruefen: hauptfenster schickt sich selber ein event
QThread::msleep(500); // QApplication::postEvent(this, new ProgressEvent(this, progress));
} // QThread::msleep(500);
} }}
} }
} else } else
if (sender == m_worker) { if (sender == m_worker) {
@ -327,8 +329,18 @@ void MainWindow::onRestartExitTimer() {
void MainWindow::onQuit() { void MainWindow::onQuit() {
m_exitTimer->stop(); m_exitTimer->stop();
qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode()); int errorCode = 0;
qApp->exit(m_worker->returnCode());
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() { void MainWindow::scrollDownTextEdit() {
@ -448,3 +460,21 @@ void MainWindow::onShowErrorMessage(QString title, QString text) {
void MainWindow::onShowStatusMessage(QString title, QString text) { void MainWindow::onShowStatusMessage(QString title, QString text) {
onShowMessage(title, 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), "");
}
}

View File

@ -34,7 +34,7 @@ public:
static const int BL_IS_UP_COUNT = 5; static const int BL_IS_UP_COUNT = 5;
static const int BL_STOP_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 *getPlugin() { return m_hw; }
hwinf const *getPlugin() const { return m_hw; } hwinf const *getPlugin() const { return m_hw; }
Update *getUpdate() { return m_update; } Update *getUpdate() { return m_update; }
@ -48,6 +48,8 @@ public slots:
void onReplaceLast(QString, QString suffix = ""); void onReplaceLast(QString, QString suffix = "");
void onShowErrorMessage(QString, QString); void onShowErrorMessage(QString, QString);
void onShowStatusMessage(QString, QString); void onShowStatusMessage(QString, QString);
void onShowErrorMessage(QStringList);
void onShowStatusMessage(QStringList);
void onStopStartTimer(); void onStopStartTimer();
void onRestartExitTimer(); void onRestartExitTimer();
void onEnableExit(); void onEnableExit();
@ -76,7 +78,7 @@ private:
QTimer *m_startTimer; QTimer *m_startTimer;
QTimer *m_exitTimer; QTimer *m_exitTimer;
bool m_progressRunning; bool m_progressRunning;
int m_progressValue; //int m_progressValue;
Update *m_update; Update *m_update;
UpdateDcEvent::UpdateStep m_updateStep; UpdateDcEvent::UpdateStep m_updateStep;
}; };

View File

@ -846,8 +846,8 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn; qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn;
res = false; res = false;
} }
m_worker->stopProgressLoop(); // m_worker->stopProgressLoop();
m_worker->setProgress(100); // m_worker->setProgress(100);
if (res == false) { if (res == false) {
break; break;

View File

@ -46,17 +46,70 @@ QString Utils::zoneName(quint8 i) {
return "N/A"; return "N/A";
} }
void Utils::printCriticalErrorMsg(QString const &errorMsg) { void Utils::printCriticalErrorMsg(QString const &errorMsg, bool upper, bool lower) {
qCritical() << QString(80, '!'); if (upper) qCritical() << QString(80, 'E');
qCritical() << errorMsg; qCritical() << errorMsg;
qCritical() << QString(80, '!');
if (lower) qCritical() << QString(80, 'E');
} }
void Utils::printInfoMsg(QString const &infoMsg) { void Utils::printCriticalErrorMsg(QStringList const &errorMsg) {
qCritical() << QString(80, '='); qCritical() << QString(80, 'E');
qCritical() << infoMsg; for (int i = 0; i < errorMsg.size(); ++i) {
qCritical() << QString(80, '='); 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) { void Utils::printLineEditInfo(QStringList const &lines) {

11
utils.h
View File

@ -8,12 +8,19 @@
#include <QFileInfo> #include <QFileInfo>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QDebug>
namespace Utils { namespace Utils {
int read1stLineOfFile(QString fileName); int read1stLineOfFile(QString fileName);
QString zoneName(quint8 i); QString zoneName(quint8 i);
void printCriticalErrorMsg(QString const &errorMsg); void printCriticalErrorMsg(QString const &errorMsg, bool upper=false, bool lower=false);
void printInfoMsg(QString const &infoMsg); 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); void printLineEditInfo(QStringList const &lines);
QString getTariffLoadTime(QString fileName); QString getTariffLoadTime(QString fileName);
QString rstrip(QString const &str); QString rstrip(QString const &str);

1482
worker.cpp

File diff suppressed because it is too large Load Diff

1116
worker.h

File diff suppressed because it is too large Load Diff