Compare commits

..

No commits in common. "6b4c4865494128e47ec90319b339df4474ff4d86" and "48073ab1f0de5b094d2c4671c087c934a83e7d4b" have entirely different histories.

7 changed files with 106 additions and 211 deletions

View File

@ -86,7 +86,7 @@ bool GitClient::gitCheckoutBranch() {
// TODO: nachsehen, ob der Branch ueberhaupt existiert
if (QDir(m_customerRepository).exists()) {
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr");
m_branchName = (zoneNr != 0)
? QString("zg1/zone%1").arg(zoneNr) : "master";
@ -165,7 +165,13 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
std::optional<QString> GitClient::gitFetch() {
if (QDir(m_customerRepository).exists()) {
qCritical() << "BRANCH NAME" << m_branchName;
// TODO
UpdateStatus status (UPDATE_STATUS::GIT_FETCH_UPDATES, "GIT FETCH UPDATES");
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT FETCH UPDATES", status.m_statusDescription));
Command c("git fetch");
if (c.execute(m_customerRepository)) {
@ -173,51 +179,36 @@ std::optional<QString> GitClient::gitFetch() {
if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n');
if (!lines.empty()) {
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:
// From https://git.mimbach49.de/GerhardHoffmann/customer_281
// 41ec581..5d25ac3 master -> origin/master
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
bool found = false;
for (int i=0; i < lines.size(); ++i) {
if (lines.at(i).contains(m_branchName)) {
found = true;
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
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);
} else {
emit m_worker->showErrorMessage("git fetch",
QString("(wrong cap-count (%1)").arg(re.captureCount()));
}
} else {
emit m_worker->showErrorMessage("git fetch",
"regex-match for commits");
}
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
QRegularExpressionMatch match = re.match(lines.last());
if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
// TODO
status = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS,
QString("GIT SUCCESSFULLY FETCHED ") + m_customerRepository);
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT_FETCH_UPDATES SUCCESS", status.m_statusDescription));
return match.captured(2);
} else {
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount();
}
}
if (!found) {
emit m_worker->showErrorMessage("git fetch",
QString("unkown branch name ") + m_branchName);
} else {
qCritical() << "ERROR NO MATCH OF COMMITS FOR 'GIT FETCH'";
}
} else {
emit m_worker->showErrorMessage("git fetch",
QString("wrong format for result of 'git fetch' ") + s);
qCritical() << "ERROR WRONG FORMAT FOR RESULT FOR 'GIT FETCH'" << s;
}
} else {
emit m_worker->showErrorMessage("git fetch",
"empty result for 'git fetch'");
qCritical() << "ERROR EMPTY RESULT FROM 'GIT FETCH'";
}
}
} else {
emit m_worker->showErrorMessage("git fetch",
QString("repository ") + m_customerRepository + " does not exist");
qCritical() << "ERROR" << m_customerRepository << "DOES NOT EXIST";
}
return std::nullopt;
}

View File

@ -146,7 +146,6 @@ int main(int argc, char *argv[]) {
MainWindow mw(&worker);
mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
mw.setWindowState(Qt::WindowFullScreen);
mw.show();
return a.exec();

View File

@ -17,25 +17,6 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
ui->updateProgress->setRange(1, 100);
ui->updateProgress->reset();
QStringList lst;
QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
lst << QString("Start: ") + start.leftJustified(m_width-10);
lst << QString("").leftJustified(m_width-3, '=');
lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3);
lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3);
lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3);
lst << QString("").leftJustified(m_width-3, '=');
ui->updateStatus->setText(lst.join('\n'));
ui->updateStatus->setEnabled(true);
ui->reserved_1->setVisible(false);
ui->reserved_2->setVisible(false);
ui->reserved_3->setVisible(false);
ui->reserved_4->setVisible(false);
ui->reserved_5->setVisible(false);
ui->reserved_6->setVisible(false);
m_startTimer = new QTimer(this);
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
m_startTimer->setSingleShot(true);
@ -47,7 +28,8 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
m_exitTimer->start(1800 * 1000);
connect(m_startTimer, SIGNAL(timeout()), ui->start, SLOT(click()));
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
//connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(click()));
connect(m_exitTimer, SIGNAL(timeout()), ui->exit, SLOT(onQuit()));
connect(ui->start, SIGNAL(clicked()), m_worker, SLOT(update()));
connect(ui->exit, SIGNAL(clicked()), this, SLOT(onQuit()));
connect(m_worker, SIGNAL(disableExit()), this, SLOT(onDisableExit()));
@ -58,6 +40,15 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
connect(m_worker, SIGNAL(showErrorMessage(QString,QString)), this, SLOT(onShowErrorMessage(QString,QString)));
connect(m_worker, SIGNAL(setProgress(quint8)), this, SLOT(onSetProgress(quint8)));
QStringList lst;
QString start = QDateTime::currentDateTime().toString(Qt::ISODate);
lst << QString("Start: ") + start.leftJustified(m_width-10);
lst << QString("").leftJustified(m_width-3, '=');
lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3);
lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3);
lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3);
lst << QString("").leftJustified(m_width-3, '=');
ui->updateStatus->setText(lst.join('\n'));
ui->updateStatus->setEnabled(true);
}
@ -86,13 +77,13 @@ void MainWindow::onRestartExitTimer() {
}
void MainWindow::onQuit() {
m_exitTimer->stop();
qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode());
// if (!m_worker->updateProcessRunning()) {
qCritical() << "ON QUIT: EXIT CODE" << QString::number(m_worker->returnCode());
qApp->exit(m_worker->returnCode());
//}
}
void MainWindow::onSetProgress(quint8 v) {
qCritical() << "ON SET PROGRESS" << v;
ui->updateProgress->setValue(v);
}
@ -118,5 +109,5 @@ void MainWindow::onAppendText(QString text, QString suffix) {
}
void MainWindow::onShowErrorMessage(QString title, QString text) {
QMessageBox::critical(this, title, text, QMessageBox::Ok);
// QMessageBox::critical(this, title, text, QMessageBox::Ok);
}

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>480</height>
<width>370</width>
<height>358</height>
</rect>
</property>
<property name="font">
@ -22,13 +22,34 @@
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>11</x>
<x>10</x>
<y>11</y>
<width>781</width>
<height>461</height>
<width>351</width>
<height>341</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QTextEdit" name="updateStatus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<family>Noto Sans</family>
<pointsize>8</pointsize>
<bold>false</bold>
</font>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QProgressBar" name="updateProgress">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="start">
<property name="font">
@ -48,87 +69,6 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="reserved_1">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="reserved_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="reserved_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QPushButton" name="reserved_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="reserved_6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QPushButton" name="reserved_5">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0" colspan="8">
<widget class="QTextEdit" name="updateStatus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<family>Noto Sans</family>
<pointsize>8</pointsize>
<bold>false</bold>
</font>
</property>
</widget>
</item>
<item row="1" column="0" colspan="8">
<widget class="QProgressBar" name="updateProgress">
<property name="value">
<number>1</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -62,11 +62,10 @@ bool Command::execute(QString workingDirectory, QStringList args) {
if (p->waitForFinished(m_waitForFinishTimeout)) {
//qDebug() << "PROCESS" << m_command << "FINISHED";
if (p->exitStatus() == QProcess::NormalExit) {
if (p->exitCode() == 0) {
return true;
} else {
qCritical() << "EXECUTED" << m_command << "with code" << p->exitCode();
}
//qInfo() << "EXECUTED" << m_command
// << "with code" << p->exitCode();
// qInfo() << "RESULT" << m_commandResult;
return true;
} else {
qCritical() << "PROCESS" << m_command << "CRASHED with code"
<< p->exitCode();

View File

@ -132,8 +132,6 @@ void Worker::privateUpdate() {
QDir customerRepository(m_customerRepository);
if (!customerRepository.exists()) {
if (m_gc.gitCloneAndCheckoutBranch()) {
emit appendText("\nInitializing customer environment", UPDATE_STEP_DONE);
m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS,
QString("CLONED AND CHECKED OUT: ") + m_customerRepository);
@ -146,17 +144,13 @@ void Worker::privateUpdate() {
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
emit setProgress(100);
m_ismasClient.setProgressInPercent(100);
emit setProgress(95);
m_ismasClient.setProgressInPercent(95);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
}
} else {
qCritical() << "CHECKOUT BRANCH...";
// checkout branch
if (m_gc.gitCheckoutBranch()) {
int progress = 10;
@ -167,56 +161,44 @@ void Worker::privateUpdate() {
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.checkoutBranch(
m_updateStatus.m_statusDescription, ""));
emit setProgress(progress);
qCritical() << "CHECKED OUT BRANCH";
if (backendConnected()) { qCritical() << "BACKEND CONNECTED";
emit setProgress(progress);
if (backendConnected()) {
progress = 20;
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (updateTriggerSet()) { qCritical() << "UPDATE TRIGGER SET";
progress = 30;
if (updateTriggerSet()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (customerEnvironment()) { qCritical() << "CUSTOMER ENVIRONMENT";
progress = 40;
if (customerEnvironment()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (filesToUpdate()) { qCritical() << "FILES TO UPDATE";
progress = 50;
if (filesToUpdate()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (updateFiles(progress)) { qCritical() << "UPDATE FILES";
progress = 60;
if (updateFiles(progress)) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (syncCustomerRepositoryAndFS()) { qCritical() << "SYNC REPOSITORY";
progress = 70;
if (syncCustomerRepositoryAndFS()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
if (sendIsmasLastVersionNotification()) { qCritical() << "SEND LAST NOTIFICATION";
progress = 80;
if (sendIsmasLastVersionNotification()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) { qCritical() << "SAVE LOG FILE";
progress = 90;
if (saveLogFile()) {
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
// mark update as activated -> this resets the WAIT button
progress = 100;
emit setProgress(progress);
m_ismasClient.setProgressInPercent(progress);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
} else {
m_returnCode = -9;
@ -246,17 +228,21 @@ void Worker::privateUpdate() {
m_returnCode = -1;
}
}
emit setProgress(100);
m_ismasClient.setProgressInPercent(100);
if (!sentIsmasLastVersionNotification) {
// try even if the backend is not connected
sendIsmasLastVersionNotification();
}
emit setProgress(100);
m_ismasClient.setProgressInPercent(100);
if (m_returnCode != 0) {
emit appendText(QString("Update process "), UPDATE_STEP_FAIL);
if (m_returnCode == 0) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
} else {
emit appendText(QString(""), UPDATE_STEP_FAIL);
}
sendIsmasLastVersionNotification();
}
m_updateProcessRunning = false;
@ -268,13 +254,11 @@ bool Worker::backendConnected() {
static int repeat = 0;
if (repeat < 3) {
qCritical() << "In backendConnected() -> #M=APISM#C=REQ_SELF#J={}";
std::optional<QString> result
= IsmasClient::sendRequestReceiveResponse(
IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_SELF#J={}");
if (result) {
QString msg = result.value();
qCritical() << "In backendConnected() -> APISM response" << msg;
QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) {
@ -297,7 +281,7 @@ bool Worker::backendConnected() {
bool ismas = obj.value("ISMAS").toBool();
QString status = obj.value("Broker").toString();
qCritical() << "In backendConnected() STATUS" << status;
qCritical() << "STATUS" << status;
if (ismas) {
if (status == "Connected") {
@ -319,8 +303,6 @@ bool Worker::backendConnected() {
}
}
}
qCritical() << "In backendConnected() ERROR";
m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_NOT_CONNECTED,
QString("NO BACKEND CONNECTION"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
@ -477,11 +459,10 @@ bool Worker::filesToUpdate() {
} else {
emit appendText(QString("\nFound 1 file to update "), UPDATE_STEP_DONE);
}
if (m_gc.gitPull()) {
emit appendText(QString("\nFetch changes files "), UPDATE_STEP_DONE);
return true;
if (!m_gc.gitPull()) {
emit showErrorMessage("files to update", "pulling files failed");
}
emit showErrorMessage("files to update", "pulling files failed");
return true;
} else {
emit showErrorMessage("files to update", "no files to update (checked-in any files?)");
}
@ -551,8 +532,7 @@ bool Worker::updateFiles(quint8 percent) {
bool Worker::syncCustomerRepositoryAndFS() {
if (QDir(m_customerRepository).exists()) {
if (QDir::setCurrent(m_customerRepository)) {
QString const params("-vv "
"--recursive "
QString const params("--recursive "
"--progress "
"--checksum "
"--exclude=.* "
@ -571,14 +551,9 @@ bool Worker::syncCustomerRepositoryAndFS() {
Command c("bash");
qInfo() << "EXECUTING CMD..." << cmd;
if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) {
QStringList result = c.getCommandResult().split('\n');
for (int i = 0; i < result.size(); ++i) {
qCritical() << result.at(i);
}
qCritical() << "SUCCESS";
qCritical() << c.getCommandResult() << "SUCCESS";
} else {
qCritical() << "CMD" << cmd << "FAILED";
qCritical() << c.getCommandResult().split('\n');
error = true;
}
}

View File

@ -157,7 +157,7 @@ public:
IsmasClient const &getIsmasClient() const { return m_ismasClient; }
bool updateProcessRunning() const { return m_updateProcessRunning; }
int returnCode() const { return m_returnCode; }
bool returnCode() const { return m_returnCode; }
int machineNr() const { return m_machineNr; }
int customerNr() const { return m_customerNr; }