Implement json-download tool with ATBUpdateTool as template.
This commit is contained in:
		@@ -3,7 +3,19 @@
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QByteArray>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <QProcess>
 | 
			
		||||
#include <QCommandLineParser>
 | 
			
		||||
#include <QStandardPaths>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
#include "message_handler.h"
 | 
			
		||||
#include "commandline_parser.h"
 | 
			
		||||
#include "utils.h"
 | 
			
		||||
#include "update.h"
 | 
			
		||||
 | 
			
		||||
#include <DeviceController/interfaces.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -16,6 +28,20 @@
 | 
			
		||||
#define SERIAL_PORT "ttyUSB0"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int read1stLineOfFile(QString fileName) {
 | 
			
		||||
    QFile f(fileName);
 | 
			
		||||
    if (f.exists()) {
 | 
			
		||||
        if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
 | 
			
		||||
            QTextStream in(&f);
 | 
			
		||||
            in.setCodec("UTF-8");
 | 
			
		||||
            while(!in.atEnd()) {
 | 
			
		||||
                return in.readLine().toInt();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv) {
 | 
			
		||||
    QByteArray const value = qgetenv("LC_ALL");
 | 
			
		||||
    if (value != "C") {
 | 
			
		||||
@@ -34,23 +60,86 @@ int main(int argc, char **argv) {
 | 
			
		||||
        setDebugLevel(LOG_NOTICE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // int r = std::system("ls -l /proc/[0-9]*/fd/* 2>/dev/null | grep /dev/ttymxc2 > /tmp/slave-or-master.txt");
 | 
			
		||||
    // lrwx------    1 root     root            64 Oct 31 14:55 /proc/884/fd/18 -> /dev/ttymxc2
 | 
			
		||||
    CommandLineParser parser;
 | 
			
		||||
    parser.process(a);
 | 
			
		||||
    parser.readSettings();
 | 
			
		||||
 | 
			
		||||
    //std::ifstream ifs("/tmp/slave-or-master.txt");
 | 
			
		||||
    QString repositoryUrl = parser.repositoryUrl();
 | 
			
		||||
    QString plugInDir = parser.plugInDir();
 | 
			
		||||
    QString plugInName = parser.plugInName();
 | 
			
		||||
    QString workingDir = parser.workingDir();
 | 
			
		||||
    QString iniFileName = parser.iniFileName();
 | 
			
		||||
    bool const dryRun = parser.dryRun();
 | 
			
		||||
    bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
 | 
			
		||||
    bool const showYoctoVersion = parser.yoctoVersion();
 | 
			
		||||
    bool const showYoctoInstallStatus = parser.yoctoInstallStatus();
 | 
			
		||||
    bool const showExtendedVersion = parser.extendedVersion();
 | 
			
		||||
    bool const alwaysDownloadConfig = parser.alwaysDownloadConfig();
 | 
			
		||||
    bool const alwaysDownloadDC = parser.alwaysDownloadDC();
 | 
			
		||||
 | 
			
		||||
    //if (ifs.is_open()) {
 | 
			
		||||
    //    std::string line;
 | 
			
		||||
    //    if (std::getline(ifs, line)) {
 | 
			
		||||
    //        if (line.size() > 0) {
 | 
			
		||||
    //            std::cout << "SLAVE " << line << std::endl;
 | 
			
		||||
    //        }
 | 
			
		||||
    //    } else {
 | 
			
		||||
    //    }
 | 
			
		||||
    QString const rtPath = QCoreApplication::applicationDirPath();
 | 
			
		||||
 | 
			
		||||
    //    ifs.close();
 | 
			
		||||
    int const machineNr = read1stLineOfFile("/mnt/system_data/machine_nr");
 | 
			
		||||
    int const customerNr = read1stLineOfFile("/mnt/system_data/cust_nr");
 | 
			
		||||
    int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
 | 
			
		||||
    QString const branchName = (zoneNr != 0)
 | 
			
		||||
            ? QString("zg1/zone%1").arg(zoneNr) : "master";
 | 
			
		||||
 | 
			
		||||
    //}
 | 
			
		||||
    qInfo() << "pwd ......................" << rtPath;
 | 
			
		||||
    qInfo() << "repositoryUrl ............" << repositoryUrl;
 | 
			
		||||
    qInfo() << "plugInDir ................" << plugInDir;
 | 
			
		||||
    qInfo() << "plugInName ..............." << plugInName;
 | 
			
		||||
    qInfo() << "workingDir ..............." << workingDir;
 | 
			
		||||
    qInfo() << "dryRun ..................." << dryRun;
 | 
			
		||||
    qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
 | 
			
		||||
    qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
 | 
			
		||||
    qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
 | 
			
		||||
    qInfo() << "showYoctoVersion ........." << showYoctoVersion;
 | 
			
		||||
    qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus;
 | 
			
		||||
    qInfo() << "showExtendedVersion ......" << showExtendedVersion;
 | 
			
		||||
    qInfo() << "iniFileName .............." << iniFileName;
 | 
			
		||||
    qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
 | 
			
		||||
    qInfo() << "machineNr ................" << machineNr;
 | 
			
		||||
    qInfo() << "customerNr ..............." << customerNr;
 | 
			
		||||
    qInfo() << "zoneNr ..................." << zoneNr;
 | 
			
		||||
 | 
			
		||||
    return a.exec();
 | 
			
		||||
    if (showExtendedVersion) {
 | 
			
		||||
        printf(APP_EXTENDED_VERSION"\n");
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QString const customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
 | 
			
		||||
 | 
			
		||||
    qCritical() << "Using customer repository" << customerRepo;
 | 
			
		||||
 | 
			
		||||
    // always execute contents of opkg_commands-file
 | 
			
		||||
    QStringList filesToUpdate;
 | 
			
		||||
 | 
			
		||||
    QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
 | 
			
		||||
 | 
			
		||||
    if (dir.exists()) {
 | 
			
		||||
        QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
 | 
			
		||||
        if (!jsons.isEmpty()) {
 | 
			
		||||
            for (QStringList::size_type i=0; i<jsons.size(); ++i) {
 | 
			
		||||
                filesToUpdate << QDir::cleanPath(QString("etc/psa_config/") + jsons.at(i));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qCritical() << "JSON FILES TO UPDATE" << filesToUpdate;
 | 
			
		||||
 | 
			
		||||
    Update update(customerRepo,
 | 
			
		||||
                  QString::number(customerNr),
 | 
			
		||||
                  branchName,
 | 
			
		||||
                  plugInDir,
 | 
			
		||||
                  plugInName,
 | 
			
		||||
                  workingDir);
 | 
			
		||||
 | 
			
		||||
    update.doUpdate(filesToUpdate);
 | 
			
		||||
 | 
			
		||||
    //return a.exec();
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user