Make python plugins appear in the logging categories list
This commit is contained in:
parent
15eead0976
commit
8aa2feb7c6
@ -330,7 +330,6 @@ bool PythonIntegrationPlugin::loadScript(const QString &scriptFile)
|
|||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
|
|
||||||
// Override stdout and stderr
|
// Override stdout and stderr
|
||||||
|
|
||||||
args = Py_BuildValue("(si)", category.toUtf8().data(), QtMsgType::QtInfoMsg);
|
args = Py_BuildValue("(si)", category.toUtf8().data(), QtMsgType::QtInfoMsg);
|
||||||
PyStdOutHandler*stdOutHandler = reinterpret_cast<PyStdOutHandler*>(PyObject_CallObject((PyObject*)&PyStdOutHandlerType, args));
|
PyStdOutHandler*stdOutHandler = reinterpret_cast<PyStdOutHandler*>(PyObject_CallObject((PyObject*)&PyStdOutHandlerType, args));
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
|
|||||||
@ -64,6 +64,7 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
ThingManagerImplementation::ThingManagerImplementation(HardwareManager *hardwareManager, const QLocale &locale, QObject *parent) :
|
ThingManagerImplementation::ThingManagerImplementation(HardwareManager *hardwareManager, const QLocale &locale, QObject *parent) :
|
||||||
ThingManager(parent),
|
ThingManager(parent),
|
||||||
@ -142,20 +143,44 @@ QStringList ThingManagerImplementation::pluginSearchDirs()
|
|||||||
QList<QJsonObject> ThingManagerImplementation::pluginsMetadata()
|
QList<QJsonObject> ThingManagerImplementation::pluginsMetadata()
|
||||||
{
|
{
|
||||||
QList<QJsonObject> pluginList;
|
QList<QJsonObject> pluginList;
|
||||||
|
QStringList searchDirs;
|
||||||
|
// Add first level of subdirectories to the plugin search dirs so we can point to a collection of plugins
|
||||||
foreach (const QString &path, pluginSearchDirs()) {
|
foreach (const QString &path, pluginSearchDirs()) {
|
||||||
|
searchDirs.append(path);
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
foreach (const QString &entry, dir.entryList()) {
|
foreach (const QString &subdir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
QFileInfo fi;
|
searchDirs.append(path + '/' + subdir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const QString &path, searchDirs) {
|
||||||
|
QDir dir(path);
|
||||||
|
qCDebug(dcThingManager) << "Loading plugins from:" << dir.absolutePath();
|
||||||
|
foreach (const QString &entry, dir.entryList({"*.so", "*.js", "*.py"}, QDir::Files)) {
|
||||||
|
|
||||||
|
QFileInfo fi(path + '/' + entry);
|
||||||
if (entry.startsWith("libnymea_integrationplugin") && entry.endsWith(".so")) {
|
if (entry.startsWith("libnymea_integrationplugin") && entry.endsWith(".so")) {
|
||||||
fi.setFile(path + "/" + entry);
|
QPluginLoader loader(fi.absoluteFilePath());
|
||||||
} else {
|
pluginList.append(loader.metaData().value("MetaData").toObject());
|
||||||
fi.setFile(path + "/" + entry + "/libnymea_integrationplugin" + entry + ".so");
|
#if QT_VERSION >= QT_VERSION_CHECK(5,12,0)
|
||||||
|
} else if (entry.startsWith("integrationplugin") && entry.endsWith(".js")) {
|
||||||
|
QFile jsonFile(fi.absolutePath() + "/" + fi.baseName() + ".json");
|
||||||
|
if (!jsonFile.open(QFile::ReadOnly)) {
|
||||||
|
qCDebug(dcThingManager()) << "Failed to open json file for:" << entry;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonFile.readAll());
|
||||||
|
pluginList.append(jsonDoc.object());
|
||||||
|
#endif
|
||||||
|
} else if (entry.startsWith("integrationplugin") && entry.endsWith(".py")) {
|
||||||
|
QFile jsonFile(fi.absolutePath() + "/" + fi.baseName() + ".json");
|
||||||
|
if (!jsonFile.open(QFile::ReadOnly)) {
|
||||||
|
qCDebug(dcThingManager()) << "Failed to open json file for:" << entry;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonFile.readAll());
|
||||||
|
pluginList.append(jsonDoc.object());
|
||||||
}
|
}
|
||||||
if (!fi.exists()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QPluginLoader loader(fi.absoluteFilePath());
|
|
||||||
pluginList.append(loader.metaData().value("MetaData").toObject());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pluginList;
|
return pluginList;
|
||||||
|
|||||||
Reference in New Issue
Block a user