getPSAInstalled():
call ptuPackagesVersion. Convert returned JSON-array into JsonObject to be appended to CMD_SENDVERSION.
This commit is contained in:
parent
7accabfa53
commit
da66d75a45
@ -18,6 +18,7 @@
|
||||
#include <Qt>
|
||||
#include <QScopedPointer>
|
||||
#include <QRegularExpression>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "message_handler.h"
|
||||
#include <DeviceController/interfaces.h>
|
||||
@ -1461,5 +1462,41 @@ PSAInstalled Worker::getPSAInstalled() {
|
||||
}
|
||||
}
|
||||
|
||||
psaInstalled.ptuPackageVersion = "{}";
|
||||
if (QFile::exists("/usr/bin/ptuPackageVersions")) {
|
||||
Command c("/usr/bin/ptuPackageVersions -i -o json");
|
||||
if (c.execute(m_workingDirectory)) {
|
||||
QString r = c.getCommandResult();
|
||||
// ptuPackageVersions returns a json-array
|
||||
QJsonArray const &ja = QJsonDocument::fromJson(r.remove(QRegExp("\\n")).toUtf8()).array();
|
||||
if (!ja.empty()) {
|
||||
// transform the array into an object, containing the objects
|
||||
// of the array (christian needs it this way)
|
||||
QJsonObject o;
|
||||
foreach (QJsonValue const &value, ja) {
|
||||
if (value.isObject()) {
|
||||
QJsonObject obj = value.toObject();
|
||||
QStringList keys = obj.keys();
|
||||
if (!keys.isEmpty()) {
|
||||
QString const &k = obj.keys().first();
|
||||
QJsonValue const &v = obj.value(k);
|
||||
o.insert(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
psaInstalled.ptuPackageVersion =
|
||||
QJsonDocument(o).toJson(QJsonDocument::Compact);
|
||||
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "ERROR array return by ptuPackageVersions empty";
|
||||
}
|
||||
} else {
|
||||
qCritical() << __func__ << ":" << __LINE__
|
||||
<< "ERROR executing ptuPackageVersions";
|
||||
}
|
||||
}
|
||||
|
||||
return psaInstalled;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user