save files with comment
This commit is contained in:
@@ -95,7 +95,13 @@ CommandLineParser::CommandLineParser()
|
||||
QCommandLineOption(
|
||||
QStringList() << "D" << "read-dc-version",
|
||||
QCoreApplication::translate("main", "Show version of device controller."),
|
||||
QCoreApplication::translate("main", "Show version of device controller."))) {
|
||||
QCoreApplication::translate("main", "Show version of device controller.")))
|
||||
, m_setPPid(
|
||||
QCommandLineOption(
|
||||
QStringList() << "P" << "set-ppid",
|
||||
QCoreApplication::translate("main", "Set pid of parent process."),
|
||||
QCoreApplication::translate("main", "Set pid of parent process."))) {
|
||||
|
||||
configure();
|
||||
}
|
||||
|
||||
@@ -154,6 +160,9 @@ void CommandLineParser::configure() {
|
||||
|
||||
m_readDCVersionOption.setDefaultValue("false");
|
||||
m_parser.addOption(m_readDCVersionOption);
|
||||
|
||||
m_setPPid.setDefaultValue("-1");
|
||||
m_parser.addOption(m_setPPid);
|
||||
}
|
||||
|
||||
void CommandLineParser::readSettings() {
|
||||
@@ -286,6 +295,19 @@ QString CommandLineParser::workingDir() {
|
||||
return m_workingDir;
|
||||
}
|
||||
|
||||
qint64 CommandLineParser::ppid() {
|
||||
m_ppid = -1;
|
||||
if (m_parser.isSet(m_setPPid)) {
|
||||
QString p = m_parser.value(m_setPPid);
|
||||
bool ok;
|
||||
qint64 q = p.toLongLong(&ok);
|
||||
if (ok) {
|
||||
m_ppid = q;
|
||||
}
|
||||
}
|
||||
return m_ppid;
|
||||
}
|
||||
|
||||
bool CommandLineParser::dryRun() {
|
||||
if (m_parser.isSet(m_dryRunOption)) {
|
||||
m_dryRun = m_parser.value(m_dryRunOption);
|
||||
|
@@ -23,6 +23,7 @@ class CommandLineParser : public QCommandLineParser {
|
||||
QString m_alwaysDownloadDC;
|
||||
QString m_readDCVersion{"false"};
|
||||
QString m_dcDir{"etc/dc/"};
|
||||
qint64 m_ppid;
|
||||
|
||||
QCommandLineOption m_repositoryUrlOption;
|
||||
QCommandLineOption m_iniFileDirectoryOption;
|
||||
@@ -41,6 +42,7 @@ class CommandLineParser : public QCommandLineParser {
|
||||
QCommandLineOption m_yoctoInstallStatusOption;
|
||||
QCommandLineOption m_dcDirectoryOption;
|
||||
QCommandLineOption m_readDCVersionOption;
|
||||
QCommandLineOption m_setPPid;
|
||||
|
||||
QCommandLineParser m_parser;
|
||||
|
||||
@@ -63,6 +65,7 @@ public:
|
||||
QString psaConfigDir();
|
||||
QString psaTariffDir();
|
||||
bool dryRun();
|
||||
qint64 ppid();
|
||||
bool noUpdatePsaHardware();
|
||||
bool yoctoVersion();
|
||||
bool yoctoInstallStatus();
|
||||
|
@@ -87,10 +87,12 @@ int main(int argc, char *argv[]) {
|
||||
if (v.isEmpty()) {
|
||||
QString sshKeyFile("/opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig");
|
||||
if (QFileInfo(sshKeyFile).exists()) {
|
||||
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
|
||||
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
|
||||
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
|
||||
return -1;
|
||||
if (qgetenv("GIT_SSH_COMMAND").isNull()) {
|
||||
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
|
||||
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
|
||||
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qCritical() << "ERROR ssh-key-file" << sshKeyFile << "does not exists. Exiting...";
|
||||
@@ -201,7 +203,7 @@ int main(int argc, char *argv[]) {
|
||||
mw.showFullScreen();
|
||||
|
||||
// test
|
||||
worker.dcUpdate();
|
||||
worker.jsUpdate();
|
||||
// worker.summary();
|
||||
|
||||
return a.exec();
|
||||
|
@@ -83,6 +83,9 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
connect(m_worker, SIGNAL(showSummary(QString)),this,SLOT(onShowSummary(QString)));
|
||||
connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit()));
|
||||
connect(m_worker, SIGNAL(showDcDownload(QString)),this,SLOT(onShowDcDownload(QString)));
|
||||
connect(m_worker, SIGNAL(showJsonDownload(QString)),this,SLOT(onShowJsonDownload(QString)));
|
||||
connect(m_worker, SIGNAL(showTariffUpdate(QString)),this,SLOT(onShowTariffUpdate(QString)));
|
||||
connect(m_worker, SIGNAL(showISMASChecks(QString)),this,SLOT(onShowISMASChecks(QString)));
|
||||
connect(m_worker, SIGNAL(setDcDownloadProgress(int)),this,SLOT(onSetDcDownloadProgress(int)));
|
||||
connect(m_worker, SIGNAL(enableExit()),this,SLOT(onEnableExit()));
|
||||
connect(m_worker, SIGNAL(stopStartTimer()),this,SLOT(onStopStartTimer()));
|
||||
@@ -105,6 +108,7 @@ void MainWindow::onShowSummary(QString text) {
|
||||
ui->updateLabel->setText(s);
|
||||
ui->updateLabel->hide();
|
||||
ui->stepLabel->hide();
|
||||
ui->updateProgress->hide();
|
||||
|
||||
s += text;
|
||||
ui->updateStatus->setText(s);
|
||||
@@ -114,10 +118,80 @@ void MainWindow::onSetDcDownloadProgress(int v) {
|
||||
ui->updateProgress->setValue(v);
|
||||
}
|
||||
|
||||
void MainWindow::onShowTariffUpdate(QString) {
|
||||
ui->exit->setEnabled(false);
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
|
||||
QString tmp("Install tariff files ");
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
|
||||
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
void MainWindow::onShowISMASChecks(QString) {
|
||||
QString s = ui->stepLabel->text();
|
||||
|
||||
QString tmp("Check ISMAS connectivity ");
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
|
||||
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
|
||||
|
||||
tmp = "Check update activation ";
|
||||
len = m_showLineLength - tmp.length();
|
||||
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
|
||||
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
void MainWindow::onShowJsonDownload(QString) {
|
||||
ui->exit->setEnabled(false);
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
|
||||
QString tmp("Send json files to dc-hardware ");
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
|
||||
s += QString("%1 <font color='Green'>[OK ]</font><br />").arg(tmp);
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
void MainWindow::onShowDcDownload(QString version) {
|
||||
m_targetDcVersion = version;
|
||||
ui->exit->setEnabled(false);
|
||||
ui->stepLabel->setText(QString("Device controller update. Target version: %1").arg(version).leftJustified(m_width-3));
|
||||
|
||||
// test
|
||||
onShowISMASChecks("");
|
||||
onShowTariffUpdate("");
|
||||
onShowJsonDownload("");
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
|
||||
QString tmp("Send dc-firmware to dc-hardware ");
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
|
||||
s += QString("%1 <font color='#33FF50'>[OK ]</font> (%2)").arg(tmp).arg(version);
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
|
@@ -52,6 +52,9 @@ public slots:
|
||||
void onEnableExit();
|
||||
void onDisableExit();
|
||||
void onShowDcDownload(QString);
|
||||
void onShowJsonDownload(QString);
|
||||
void onShowTariffUpdate(QString);
|
||||
void onShowISMASChecks(QString);
|
||||
void onSetDcDownloadProgress(int);
|
||||
void onShowSummary(QString);
|
||||
#if EMERGENCY_LEAVE_BL==1
|
||||
@@ -68,6 +71,9 @@ private slots:
|
||||
void onQuit();
|
||||
|
||||
private:
|
||||
|
||||
int const m_showLineLength = 37;
|
||||
|
||||
void scrollDownTextEdit();
|
||||
void onShowMessage(QString, QString);
|
||||
|
||||
|
@@ -37,6 +37,7 @@ void Command::readyReadStandardOutput() {
|
||||
QProcess *p = (QProcess *)sender();
|
||||
if (p) {
|
||||
QString s = p->readAllStandardOutput();
|
||||
|
||||
if (m_worker) {
|
||||
int i = -1;
|
||||
if ((i = s.indexOf("<DC-VERSION>")) != -1) {
|
||||
@@ -49,9 +50,9 @@ void Command::readyReadStandardOutput() {
|
||||
}
|
||||
emit m_worker->showDcDownload(s);
|
||||
} else
|
||||
if ((i = s.indexOf("<PROGRESS>")) != -1) {
|
||||
if ((i = s.indexOf("<DC-PROGRESS>")) != -1) {
|
||||
bool ok;
|
||||
int v = s.mid(i+10).trimmed().toInt(&ok);
|
||||
int v = s.mid(i+13).trimmed().toInt(&ok);
|
||||
if (ok) {
|
||||
emit m_worker->setDcDownloadProgress(v);
|
||||
emit m_worker->insertText(s.mid(0,i) + "\n");
|
||||
@@ -67,6 +68,14 @@ void Command::readyReadStandardOutput() {
|
||||
if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) {
|
||||
m_worker->summary();
|
||||
//qApp->exit(-1);
|
||||
} else
|
||||
if ((i = s.indexOf("<JS-PROGRESS>")) != -1) {
|
||||
bool ok;
|
||||
int v = s.mid(i+13).trimmed().toInt(&ok);
|
||||
if (ok) {
|
||||
emit m_worker->setDcDownloadProgress(v);
|
||||
emit m_worker->insertText(s.mid(0,i) + "\n");
|
||||
}
|
||||
} else {
|
||||
emit m_worker->insertText(s);
|
||||
}
|
||||
@@ -93,6 +102,11 @@ void Command::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
|
||||
}
|
||||
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput()));
|
||||
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
|
||||
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
|
||||
|
||||
if (m_command.contains("ATBDownloadDCJsonFiles")) {
|
||||
m_worker->dcUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
bool Command::start(QString workingDirectory, QStringList args) {
|
||||
@@ -104,12 +118,16 @@ bool Command::start(QString workingDirectory, QStringList args) {
|
||||
if (m_p != nullptr) {
|
||||
delete m_p;
|
||||
}
|
||||
|
||||
qCritical() << "COMMAND" << m_command << workingDirectory << args;
|
||||
|
||||
m_p = new QProcess(this);
|
||||
m_p->setWorkingDirectory(workingDirectory);
|
||||
m_p->setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
connect(m_p, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
|
||||
connect(m_p, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
|
||||
connect(m_p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
|
||||
|
||||
if (!args.isEmpty()) {
|
||||
m_p->start(m_command, args);
|
||||
|
@@ -18,9 +18,99 @@
|
||||
#include <QJsonValue>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QStringList>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
QVector<QPair<QString, QString>> Utils::installedJsonFiles(QDir const &customerDir) {
|
||||
QVector<QPair<QString, QString>> vec;
|
||||
QStringList fileList;
|
||||
|
||||
QDirIterator it(QDir::cleanPath(customerDir.absolutePath() + QDir::separator() + "etc/psa_config"));
|
||||
while (it.hasNext()) {
|
||||
QFileInfo const fi(it.next());
|
||||
if (fi.fileName().startsWith("DC2C") && fi.fileName().endsWith(".json")) {
|
||||
fileList << fi.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
fileList.sort();
|
||||
|
||||
QString const ¤t = QDir::current().absolutePath();
|
||||
|
||||
if (!QDir::setCurrent(customerDir.absolutePath())) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
|
||||
<< "working directory to" << customerDir.absolutePath();
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < fileList.size(); ++i) {
|
||||
|
||||
QProcess p;
|
||||
QStringList params;
|
||||
params << "-c" << "git log -n 1 --pretty=format:%H -- " << fileList[i];
|
||||
|
||||
p.start("bash", params);
|
||||
p.waitForFinished();
|
||||
QString r = p.readAllStandardOutput().left(8);
|
||||
|
||||
vec.push_back(QPair<QString, QString>(QFileInfo(fileList[i]).fileName(), r));
|
||||
}
|
||||
|
||||
if (!QDir::setCurrent(current)) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
|
||||
<< "working directory to" << current;
|
||||
}
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
QVector<QPair<QString, QString>> Utils::installedTariffFiles(QDir const &customerDir) {
|
||||
QVector<QPair<QString, QString>> vec;
|
||||
QStringList fileList;
|
||||
|
||||
QDirIterator it(QDir::cleanPath(customerDir.absolutePath() + QDir::separator() + "etc/psa_tariff"));
|
||||
while (it.hasNext()) {
|
||||
QFileInfo const fi(it.next());
|
||||
if (fi.fileName().startsWith("tariff") && fi.fileName().endsWith(".json")) {
|
||||
fileList << fi.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
fileList.sort();
|
||||
|
||||
QString const ¤t = QDir::current().absolutePath();
|
||||
|
||||
if (!QDir::setCurrent(customerDir.absolutePath())) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
|
||||
<< "working directory to" << customerDir.absolutePath();
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < fileList.size(); ++i) {
|
||||
|
||||
QProcess p;
|
||||
QStringList params;
|
||||
params << "-c" << "git log -n 1 --pretty=format:%H -- " << fileList[i];
|
||||
|
||||
qCritical() << current << "git log -n 1 --pretty=format:%H -- " << fileList[i];
|
||||
|
||||
p.start("bash", params);
|
||||
p.waitForFinished();
|
||||
QString r = p.readAllStandardOutput().left(8);
|
||||
|
||||
vec.push_back(QPair<QString, QString>(QFileInfo(fileList[i]).fileName(), r));
|
||||
}
|
||||
|
||||
if (!QDir::setCurrent(current)) {
|
||||
qCritical() << __func__ << ":" << __LINE__ << ": ERROR: can not set"
|
||||
<< "working directory to" << current;
|
||||
}
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
QVector<QPair<QString, QString>> Utils::installedPackages() {
|
||||
QVector<QPair<QString, QString>> vec;
|
||||
if (QFile::exists("/usr/bin/ptuPackageVersions")) {
|
||||
@@ -165,7 +255,7 @@ QString Utils::getTariffInfo(QString fileName) {
|
||||
|
||||
}
|
||||
|
||||
QString Utils::zoneName(quint8 i) {
|
||||
QString Utils::zoneName(quint8 /* i */) {
|
||||
//static constexpr char const *zName[] = {
|
||||
// "",
|
||||
// "purple",
|
||||
|
@@ -36,6 +36,8 @@ namespace Utils {
|
||||
bool isATBQTRunning();
|
||||
|
||||
QVector<QPair<QString, QString>> installedPackages();
|
||||
QVector<QPair<QString, QString>> installedJsonFiles(QDir const &customerDir);
|
||||
QVector<QPair<QString, QString>> installedTariffFiles(QDir const &customerDir);
|
||||
}
|
||||
|
||||
#endif // UTILS_H_INCLUDED
|
||||
|
@@ -178,12 +178,15 @@ Worker::Worker(int customerNr,
|
||||
, m_updateProcessRunning(true)
|
||||
, m_mainWindow(nullptr) /* contains plugin */
|
||||
, m_dcDownloadFirmware(new Command("/opt/app/tools/atbupdate/ATBDownloadDCFirmware --read-dc-version true"))
|
||||
, m_dcDownloadJsonFiles(new Command(
|
||||
QString("/opt/app/tools/atbupdate/ATBDownloadDCJsonFiles --set-ppid %1").arg(QCoreApplication::applicationPid())))
|
||||
//, m_withoutIsmasDirectPort(true) /* useful for testing */ {
|
||||
, m_withoutIsmasDirectPort(false) /* useful for testing */ {
|
||||
|
||||
|
||||
m_start = QDateTime::currentDateTime();
|
||||
m_dcDownloadFirmware->setWorker(this);
|
||||
m_dcDownloadJsonFiles->setWorker(this);
|
||||
|
||||
// TODO: turn object into singleton
|
||||
instance = this;
|
||||
@@ -1511,6 +1514,10 @@ PSAInstalled Worker::getPSAInstalled() {
|
||||
return psaInstalled;
|
||||
}
|
||||
|
||||
bool Worker::jsUpdate() {
|
||||
return m_dcDownloadJsonFiles->start("/opt/app/tools/atbupdate");
|
||||
}
|
||||
|
||||
bool Worker::dcUpdate() {
|
||||
return m_dcDownloadFirmware->start("/opt/app/tools/atbupdate");
|
||||
}
|
||||
@@ -1520,6 +1527,9 @@ void Worker::summary() {
|
||||
QString summary, first, second, line, tmp;
|
||||
QVector<QPair<QString, QString>> vec = Utils::installedPackages();
|
||||
|
||||
vec.append(Utils::installedTariffFiles(m_customerRepository));
|
||||
vec.append(Utils::installedJsonFiles(m_customerRepository));
|
||||
|
||||
int max_first = 0, max_second = 0;
|
||||
for (int i = 0; i < vec.size(); ++i) {
|
||||
max_first = std::max(max_first, vec[i].first.length());
|
||||
@@ -1584,4 +1594,5 @@ void Worker::summary() {
|
||||
}
|
||||
|
||||
emit showSummary(summary);
|
||||
emit enableExit();
|
||||
}
|
||||
|
@@ -191,6 +191,7 @@ class Worker : public QThread{
|
||||
|
||||
MainWindow *m_mainWindow;
|
||||
Command *m_dcDownloadFirmware;
|
||||
Command *m_dcDownloadJsonFiles;
|
||||
bool m_withoutIsmasDirectPort;
|
||||
QString m_apismVersion;
|
||||
|
||||
@@ -460,6 +461,7 @@ public:
|
||||
Update *update() { return m_update; }
|
||||
Update const *update() const { return m_update; }
|
||||
|
||||
bool jsUpdate();
|
||||
bool dcUpdate();
|
||||
void summary();
|
||||
QDateTime start() { return m_start; }
|
||||
@@ -478,6 +480,9 @@ signals:
|
||||
void enableExit();
|
||||
void disableExit();
|
||||
void showDcDownload(QString);
|
||||
void showJsonDownload(QString);
|
||||
void showTariffUpdate(QString);
|
||||
void showISMASChecks(QString);
|
||||
void showSummary(QString);
|
||||
void setDcDownloadProgress(int);
|
||||
|
||||
|
Reference in New Issue
Block a user