From c354b752b87829bc16f1c7629539a529f481f97f Mon Sep 17 00:00:00 2001 From: houchengqiu Date: Thu, 26 Oct 2023 20:10:59 +0800 Subject: [PATCH] fix: fix cli export kwin log failed problem fix cli export kwin log failed problem Log: fix cli export kwin log failed problem Bug: https://pms.uniontech.com/bug-view-225427.html --- application/dbusmanager.cpp | 79 +++++++++++++++++++++++++++++----- application/dbusmanager.h | 3 +- application/displaycontent.cpp | 4 ++ application/logbackend.cpp | 2 +- application/main.cpp | 8 +++- 5 files changed, 82 insertions(+), 14 deletions(-) diff --git a/application/dbusmanager.cpp b/application/dbusmanager.cpp index a0b5ca9b..3776ed26 100644 --- a/application/dbusmanager.cpp +++ b/application/dbusmanager.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef QT_DEBUG Q_LOGGING_CATEGORY(logDBusManager, "org.deepin.log.viewer.dbus.manager") @@ -55,6 +56,58 @@ QString DBusManager::getSystemInfo() return isklusystemName; } +//根据命令行 dmidecode -s system-product-name|awk '{print SNF}' 返回的结果判断是否是华为电脑 +bool DBusManager::isHuaWei() +{ + QStringList options; + options << QString(QStringLiteral("-c")); + options << QString(QStringLiteral("dmidecode -s system-product-name|awk '{print $NF}'")); + QProcess process; + process.start(QString(QStringLiteral("bash")), options); + process.waitForFinished(); + process.waitForReadyRead(); + QByteArray tempArray = process.readAllStandardOutput(); + char *charTemp = tempArray.data(); + QString str_output = QString(QLatin1String(charTemp)); + process.close(); + //qInfo() << "system-product-name: " << str_output; + options.clear(); + options << QString(QStringLiteral("-c")); + options << QString(QStringLiteral("dmidecode | grep -i \"String 4\"")); + process.start(QString(QStringLiteral("bash")), options); + process.waitForFinished(); + process.waitForReadyRead(); + QString str_output1 = QString(QLatin1String(process.readAllStandardOutput().data())); + //qInfo() << "dmidecode | grep -i \"String 4\": " << str_output1; + if (str_output.contains("KLVV", Qt::CaseInsensitive) || + str_output.contains("KLVU", Qt::CaseInsensitive) || + str_output.contains("PGUV", Qt::CaseInsensitive) || + str_output.contains("PGUW", Qt::CaseInsensitive) || + str_output1.contains("PWC30", Qt::CaseInsensitive) || + str_output.contains("L540", Qt::CaseInsensitive) || + str_output.contains("W585", Qt::CaseInsensitive) || + isPangu()) + return true; + return false; +} + +bool DBusManager::isPangu() +{ + QDBusInterface systemInfoInterface("com.deepin.daemon.SystemInfo", + "/com/deepin/daemon/SystemInfo", + "org.freedesktop.DBus.Properties", + QDBusConnection::sessionBus()); + QDBusMessage replyCpu = systemInfoInterface.call("Get", "com.deepin.daemon.SystemInfo", "CPUHardware"); + QList outArgsCPU = replyCpu.arguments(); + if (outArgsCPU.count()) { + QString CPUHardware = outArgsCPU.at(0).value().variant().toString(); + if (CPUHardware.contains("PANGU")) { + return true; + } + } + return false; +} + bool DBusManager::isSEOepn() { bool bIsSEOpen = false; @@ -100,24 +153,28 @@ bool DBusManager::isAuditAdmin() } bool DBusManager::isSpecialComType(){ - qCDebug(logDBusManager) << "Utils::specialComType:" << Utils::specialComType; bool isSpecialComType = false; //机器类型未知时,走以前判读机器的类型,有可能是通过DConfig获取失败,导致机器类型未知 if(Utils::specialComType != -1){ isSpecialComType = Utils::specialComType ? true:false; }else{ QString systemName = getSystemInfo(); - qCDebug(logDBusManager) << "systemName:" << systemName; - if (systemName == "klu" || - systemName == "panguV" || - systemName == "W515 PGUV-WBY0" || - systemName == "pangu" || - systemName.toUpper().contains("PGUV") || - systemName.toUpper().contains("PANGUV") || - systemName.toUpper().contains("KLU") || - systemName.toUpper().contains("PANGU")) { - isSpecialComType = true; + if (!systemName.isEmpty()) { + if (systemName == "klu" || + systemName == "panguV" || + systemName == "W515 PGUV-WBY0" || + systemName == "pangu" || + systemName.toUpper().contains("PGUV") || + systemName.toUpper().contains("PANGUV") || + systemName.toUpper().contains("KLU") || + systemName.toUpper().contains("PANGU")) { + isSpecialComType = true; + } } + + // 上一dbus服务可能在新版本已失效,使用dmidecode命令再判断一次 + if (!isSpecialComType) + isSpecialComType = isHuaWei(); } return isSpecialComType; } diff --git a/application/dbusmanager.h b/application/dbusmanager.h index 9de16f5a..3aa34996 100644 --- a/application/dbusmanager.h +++ b/application/dbusmanager.h @@ -16,6 +16,8 @@ class DBusManager : public QObject public: explicit DBusManager(QObject *parent = nullptr); static QString getSystemInfo(); + static bool isHuaWei(); + static bool isPangu(); // 是否开启等保四 static bool isSEOepn(); // 开启等保四情况下,判断是否为审计管理员身份 @@ -27,7 +29,6 @@ class DBusManager : public QObject static bool isSpecialComType(); static bool isGetedKlu ; static QString isklusystemName ; - signals: public slots: diff --git a/application/displaycontent.cpp b/application/displaycontent.cpp index b6d7c561..2106d2a6 100644 --- a/application/displaycontent.cpp +++ b/application/displaycontent.cpp @@ -1511,6 +1511,10 @@ void DisplayContent::slot_BtnSelected(int btnId, int lId, QModelIndex idx) generateDnfFile(BUTTONID(m_curBtnId), m_curDnfLevel); } else if (treeData.contains(DMESG_TREE_DATA, Qt::CaseInsensitive)) { generateDmesgFile(BUTTONID(m_curBtnId), PRIORITY(m_curLevel)); + } else if (treeData.contains(KWIN_TREE_DATA, Qt::CaseInsensitive)) { + KWIN_FILTERS filter; + filter.msg = ""; + generateKwinFile(filter); } else if (treeData.contains(AUDIT_TREE_DATA, Qt::CaseInsensitive)) { generateAuditFile(BUTTONID(m_curBtnId), AUDITTYPE(m_curLevel)); } else if(treeData.contains(COREDUMP_TREE_DATA, Qt::CaseInsensitive)) { diff --git a/application/logbackend.cpp b/application/logbackend.cpp index a74cc780..1e042a33 100644 --- a/application/logbackend.cpp +++ b/application/logbackend.cpp @@ -1512,7 +1512,7 @@ BUTTONID LogBackend::period2Enum(const QString &period) BUTTONID id = INVALID; if (period == "all") id = ALL; - else if (period == "today" || period == "1d") + else if (period == "today") id = ONE_DAY; else if (period == "3d") id = THREE_DAYS; diff --git a/application/main.cpp b/application/main.cpp index 4318c84f..b8c70b13 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -171,7 +171,13 @@ int main(int argc, char *argv[]) else bRet = LogBackend::instance(&a)->exportTypeLogsByCondition(outDir, type, period, event, keyword); } else if (TYPE_XORG == type || TYPE_OTHER == type || TYPE_CUSTOM == type || TYPE_KWIN == type) { - // Xorg、其他、自定义日志 不能按条件导出 + // Xorg、Kwin 只能按关键字导出 + if (!period.isEmpty() || !level.isEmpty() || !status.isEmpty() || !event.isEmpty()) + qCWarning(logAppMain) << QString("Export logs by %1, can only be filtered using 'keyword' parameters.").arg(type); + else + bRet = LogBackend::instance(&a)->exportTypeLogsByCondition(outDir, type, period, event, keyword); + } else if (TYPE_OTHER == type || TYPE_CUSTOM == type) { + // 其他、自定义日志 不能按条件导出 if (!period.isEmpty() || !level.isEmpty() || !status.isEmpty() || !event.isEmpty()) qCWarning(logAppMain) << QString("Export logs by %1, cannot be filtered by any parameters.").arg(type); } else {