From 301c87c40c3b76eb0bd6692f231ed5600b2239bd Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 2 Feb 2021 20:14:32 +0100 Subject: [PATCH] rougly working script feed generating --- resources/docs/Feed-formats.md | 4 +++- resources/scripts/7za | 2 +- .../miscellaneous/databasequeries.cpp | 4 ++-- .../standard/gui/standardfeeddetails.cpp | 23 +++++++++++++++---- .../standard/gui/standardfeeddetails.h | 1 + .../services/standard/standardfeed.cpp | 22 ++++++++++++------ 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/resources/docs/Feed-formats.md b/resources/docs/Feed-formats.md index 16318e7d8..313a62ec1 100755 --- a/resources/docs/Feed-formats.md +++ b/resources/docs/Feed-formats.md @@ -61,4 +61,6 @@ Also, working directory of process executing the script is set to RSS Guard's us After your source feed data are downloaded either via URL or custom script, you can optionally post-process the data with one more custom script, which will take raw source data as input and must produce processed feed data to **standard output** while printing all error messages to **error output**. -Formatting of post-process script execution line is the same as above. \ No newline at end of file +Typical post-processing filter might do things like advanced CSS formatting of feed file entries, removing some ads etc. + +Format of post-process script execution line is the same as above. \ No newline at end of file diff --git a/resources/scripts/7za b/resources/scripts/7za index 47f412575..9c10723bf 160000 --- a/resources/scripts/7za +++ b/resources/scripts/7za @@ -1 +1 @@ -Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9 +Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749 diff --git a/src/librssguard/miscellaneous/databasequeries.cpp b/src/librssguard/miscellaneous/databasequeries.cpp index cef60d9bf..7db3a442e 100755 --- a/src/librssguard/miscellaneous/databasequeries.cpp +++ b/src/librssguard/miscellaneous/databasequeries.cpp @@ -2107,7 +2107,7 @@ int DatabaseQueries::addStandardFeed(const QSqlDatabase& db, int parent_id, int q.bindValue(QSL(":encoding"), encoding); q.bindValue(QSL(":url"), url); q.bindValue(QSL(":source_type"), int(source_type)); - q.bindValue(QSL(":post_process"), post_process_script); + q.bindValue(QSL(":post_process"), post_process_script.simplified()); q.bindValue(QSL(":protected"), is_protected ? 1 : 0); q.bindValue(QSL(":username"), username); q.bindValue(QSL(":account_id"), account_id); @@ -2171,7 +2171,7 @@ bool DatabaseQueries::editStandardFeed(const QSqlDatabase& db, int parent_id, in q.bindValue(QSL(":encoding"), encoding); q.bindValue(QSL(":url"), url); q.bindValue(QSL(":source_type"), int(source_type)); - q.bindValue(QSL(":post_process"), post_process_script); + q.bindValue(QSL(":post_process"), post_process_script.simplified()); q.bindValue(QSL(":protected"), is_protected ? 1 : 0); q.bindValue(QSL(":username"), username); diff --git a/src/librssguard/services/standard/gui/standardfeeddetails.cpp b/src/librssguard/services/standard/gui/standardfeeddetails.cpp index e39cc3a91..2c0dc30c1 100755 --- a/src/librssguard/services/standard/gui/standardfeeddetails.cpp +++ b/src/librssguard/services/standard/gui/standardfeeddetails.cpp @@ -85,6 +85,7 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) { onUrlChanged(m_ui.m_txtSource->lineEdit()->text()); }); connect(m_ui.m_txtSource->lineEdit(), &BaseLineEdit::textChanged, this, &StandardFeedDetails::onUrlChanged); + connect(m_ui.m_txtPostProcessScript->lineEdit(), &BaseLineEdit::textChanged, this, &StandardFeedDetails::onPostProcessScriptChanged); connect(m_actionLoadIconFromFile, &QAction::triggered, this, &StandardFeedDetails::onLoadIconFromFile); connect(m_actionUseDefaultIcon, &QAction::triggered, this, &StandardFeedDetails::onUseDefaultIcon); @@ -100,9 +101,10 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) { GuiUtilities::setLabelAsNotice(*m_ui.m_lblScriptInfo, false); - onTitleChanged(QString()); - onDescriptionChanged(QString()); - onUrlChanged(QString()); + onTitleChanged({}); + onDescriptionChanged({}); + onUrlChanged({}); + onPostProcessScriptChanged({}); } void StandardFeedDetails::guessIconOnly(const QString& url, const QString& username, @@ -219,7 +221,7 @@ void StandardFeedDetails::onUrlChanged(const QString& new_url) { m_ui.m_txtSource->setStatus(LineEditWithStatus::StatusType::Ok, tr("The source is ok.")); } else if (!new_url.simplified().isEmpty()) { - m_ui.m_txtSource->setStatus(LineEditWithStatus::StatusType::Warning, + m_ui.m_txtSource->setStatus(LineEditWithStatus::StatusType::Error, tr("The source needs to include \"#\" separator.")); } else { @@ -231,6 +233,19 @@ void StandardFeedDetails::onUrlChanged(const QString& new_url) { } } +void StandardFeedDetails::onPostProcessScriptChanged(const QString& new_pp) { + if (QRegularExpression(SCRIPT_SOURCE_TYPE_REGEXP).match(new_pp).hasMatch()) { + m_ui.m_txtPostProcessScript->setStatus(LineEditWithStatus::StatusType::Ok, tr("The source is ok.")); + } + else if (!new_pp.simplified().isEmpty()) { + m_ui.m_txtPostProcessScript->setStatus(LineEditWithStatus::StatusType::Error, + tr("The source needs to include \"#\" separator.")); + } + else { + m_ui.m_txtPostProcessScript->setStatus(LineEditWithStatus::StatusType::Ok, tr("The source is empty.")); + } +} + void StandardFeedDetails::onLoadIconFromFile() { QFileDialog dialog(this, tr("Select icon file for the feed"), qApp->homeFolder(), tr("Images (*.bmp *.jpg *.jpeg *.png *.svg *.tga)")); diff --git a/src/librssguard/services/standard/gui/standardfeeddetails.h b/src/librssguard/services/standard/gui/standardfeeddetails.h index cabfbb8ab..d9cb67b3f 100755 --- a/src/librssguard/services/standard/gui/standardfeeddetails.h +++ b/src/librssguard/services/standard/gui/standardfeeddetails.h @@ -35,6 +35,7 @@ class StandardFeedDetails : public QWidget { void onTitleChanged(const QString& new_title); void onDescriptionChanged(const QString& new_description); void onUrlChanged(const QString& new_url); + void onPostProcessScriptChanged(const QString& new_pp); void onLoadIconFromFile(); void onUseDefaultIcon(); diff --git a/src/librssguard/services/standard/standardfeed.cpp b/src/librssguard/services/standard/standardfeed.cpp index d5330ea4f..a5c9feb90 100644 --- a/src/librssguard/services/standard/standardfeed.cpp +++ b/src/librssguard/services/standard/standardfeed.cpp @@ -4,6 +4,7 @@ #include "core/feedsmodel.h" #include "definitions/definitions.h" +#include "exceptions/applicationexception.h" #include "gui/feedmessageviewer.h" #include "gui/feedsview.h" #include "miscellaneous/databasequeries.h" @@ -563,15 +564,14 @@ QString StandardFeed::generateFeedFileWithScript(const QString& execution_line, process.setWorkingDirectory(qApp->userDataFolder()); process.setProgram(prepared_query.first); -//#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) -// process.setNativeArguments(prepared_query.second); -//#else +#if defined(Q_OS_WIN) + process.setNativeArguments(prepared_query.second); +#else process.setArguments({ prepared_query.second }); - -//#endif +#endif if (!process.open() || process.error() == QProcess::ProcessError::FailedToStart) { - return ""; + throw ApplicationException(QSL("process failed to start")); } if (process.waitForFinished(run_timeout)) { @@ -581,7 +581,15 @@ QString StandardFeed::generateFeedFileWithScript(const QString& execution_line, } else { process.kill(); - return ""; + + auto raw_error = process.readAllStandardError(); + + if (raw_error.simplified().isEmpty()) { + throw ApplicationException(QSL("process failed to finish properly")); + } + else { + throw ApplicationException(QString(raw_error)); + } } }