From d52c6230e9d18153108bd6d1cfa6fdbef76915e1 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 2 Nov 2018 23:55:18 +0800 Subject: [PATCH 1/3] Fix defects found by lgtm.com --- src/searchengine/nova/helpers.py | 4 ++-- src/searchengine/nova/nova2.py | 8 ++++---- src/searchengine/nova/nova2dl.py | 4 ++-- src/searchengine/nova/novaprinter.py | 6 +++--- src/searchengine/nova3/helpers.py | 4 ++-- src/searchengine/nova3/nova2.py | 8 ++++---- src/searchengine/nova3/nova2dl.py | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/searchengine/nova/helpers.py b/src/searchengine/nova/helpers.py index cb236f220..409dd95d4 100644 --- a/src/searchengine/nova/helpers.py +++ b/src/searchengine/nova/helpers.py @@ -1,4 +1,4 @@ -#VERSION: 1.42 +#VERSION: 1.43 # Author: # Christophe DUMEZ (chris@qbittorrent.org) @@ -90,7 +90,7 @@ def retrieve_url(url): charset = 'utf-8' try: ignore, charset = info['Content-Type'].split('charset=') - except: + except Exception: pass dat = dat.decode(charset, 'replace') dat = htmlentitydecode(dat) diff --git a/src/searchengine/nova/nova2.py b/src/searchengine/nova/nova2.py index c286d0331..10453846e 100644 --- a/src/searchengine/nova/nova2.py +++ b/src/searchengine/nova/nova2.py @@ -1,4 +1,4 @@ -#VERSION: 1.42 +#VERSION: 1.43 # Author: # Fabien Devaux @@ -77,7 +77,7 @@ def initialize_engines(): # bind class name globals()[engi] = getattr(engine_module, engi) supported_engines.append(engi) - except: + except Exception: pass return supported_engines @@ -94,7 +94,7 @@ def engines_to_xml(supported_engines): if hasattr(search_engine, "supported_categories"): supported_categories = " ".join((key for key in search_engine.supported_categories.keys() - if key is not "all")) + if key != "all")) yield "".join((tab, "<", short_name, ">\n", tab, tab, "", search_engine.name, "\n", @@ -138,7 +138,7 @@ def run_search(engine_list): else: engine.search(what) return True - except: + except Exception: return False diff --git a/src/searchengine/nova/nova2dl.py b/src/searchengine/nova/nova2dl.py index 862270d86..c04a43749 100644 --- a/src/searchengine/nova/nova2dl.py +++ b/src/searchengine/nova/nova2dl.py @@ -1,4 +1,4 @@ -#VERSION: 1.21 +#VERSION: 1.22 # Author: # Christophe DUMEZ (chris@qbittorrent.org) @@ -45,7 +45,7 @@ for engine in engines: exec("from engines.%s import %s" % (e, e)) exec("engine_url = %s.url" % e) supported_engines[engine_url] = e - except: + except Exception: pass if __name__ == '__main__': diff --git a/src/searchengine/nova/novaprinter.py b/src/searchengine/nova/novaprinter.py index 502d5e4e8..bfd9615f5 100644 --- a/src/searchengine/nova/novaprinter.py +++ b/src/searchengine/nova/novaprinter.py @@ -1,4 +1,4 @@ -#VERSION: 1.46 +#VERSION: 1.47 # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -51,13 +51,13 @@ def anySizeToBytes(size_string): # separate integer from unit try: size, unit = size_string.split() - except: + except Exception: try: size = size_string.strip() unit = ''.join([c for c in size if c.isalpha()]) if len(unit) > 0: size = size[:-len(unit)] - except: + except Exception: return -1 if len(size) == 0: return -1 diff --git a/src/searchengine/nova3/helpers.py b/src/searchengine/nova3/helpers.py index f830b4365..f17dad5af 100644 --- a/src/searchengine/nova3/helpers.py +++ b/src/searchengine/nova3/helpers.py @@ -1,4 +1,4 @@ -#VERSION: 1.41 +#VERSION: 1.42 # Author: # Christophe DUMEZ (chris@qbittorrent.org) @@ -90,7 +90,7 @@ def retrieve_url(url): charset = 'utf-8' try: ignore, charset = info['Content-Type'].split('charset=') - except: + except Exception: pass dat = dat.decode(charset, 'replace') dat = htmlentitydecode(dat) diff --git a/src/searchengine/nova3/nova2.py b/src/searchengine/nova3/nova2.py index 5f49f99b6..0b11e3cdd 100644 --- a/src/searchengine/nova3/nova2.py +++ b/src/searchengine/nova3/nova2.py @@ -1,4 +1,4 @@ -#VERSION: 1.42 +#VERSION: 1.43 # Author: # Fabien Devaux @@ -76,7 +76,7 @@ def initialize_engines(): # bind class name globals()[engi] = getattr(engine_module, engi) supported_engines.append(engi) - except: + except Exception: pass return supported_engines @@ -93,7 +93,7 @@ def engines_to_xml(supported_engines): if hasattr(search_engine, "supported_categories"): supported_categories = " ".join((key for key in search_engine.supported_categories.keys() - if key is not "all")) + if key != "all")) yield "".join((tab, "<", short_name, ">\n", tab, tab, "", search_engine.name, "\n", @@ -138,7 +138,7 @@ def run_search(engine_list): engine.search(what) return True - except: + except Exception: return False diff --git a/src/searchengine/nova3/nova2dl.py b/src/searchengine/nova3/nova2dl.py index 862270d86..c04a43749 100644 --- a/src/searchengine/nova3/nova2dl.py +++ b/src/searchengine/nova3/nova2dl.py @@ -1,4 +1,4 @@ -#VERSION: 1.21 +#VERSION: 1.22 # Author: # Christophe DUMEZ (chris@qbittorrent.org) @@ -45,7 +45,7 @@ for engine in engines: exec("from engines.%s import %s" % (e, e)) exec("engine_url = %s.url" % e) supported_engines[engine_url] = e - except: + except Exception: pass if __name__ == '__main__': From ee030cc4eb56c1e72b09a11f0dd8ddbdaaba230f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 3 Nov 2018 00:13:31 +0800 Subject: [PATCH 2/3] Fix wrong type passed to arg() --- src/base/search/searchpluginmanager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index 5a678745e..c5df002a7 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -518,10 +518,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info) } } - if (numCorrectData < lines.size()) - emit checkForUpdatesFailed(tr("Incorrect update info received for %1 out of %2 plugins.").arg((lines.size() - numCorrectData), lines.size())); - else + if (numCorrectData < lines.size()) { + emit checkForUpdatesFailed(tr("Incorrect update info received for %1 out of %2 plugins.") + .arg(QString::number(lines.size() - numCorrectData), QString::number(lines.size()))); + } + else { emit checkForUpdatesFinished(updateInfo); + } } bool SearchPluginManager::isUpdateNeeded(QString pluginName, PluginVersion newVersion) const From c1c28ce195714cc5e2e75bfabc01f3926211ca95 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 3 Nov 2018 00:30:21 +0800 Subject: [PATCH 3/3] Improve parser for search engine versions.txt The parse could fail when there is an extra empty line at the end of file, this patch fixes it. --- src/base/search/searchpluginmanager.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index c5df002a7..c72aa46df 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -47,6 +47,7 @@ #include "base/net/downloadmanager.h" #include "base/preferences.h" #include "base/profile.h" +#include "base/utils/bytearray.h" #include "base/utils/foreignapps.h" #include "base/utils/fs.h" #include "base/utils/misc.h" @@ -495,25 +496,24 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info) { QHash updateInfo; int numCorrectData = 0; - QList lines = info.split('\n'); - foreach (QByteArray line, lines) { + + const QList lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); + for (QByteArray line : lines) { line = line.trimmed(); if (line.isEmpty()) continue; if (line.startsWith('#')) continue; - QList list = line.split(' '); + const QList list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); if (list.size() != 2) continue; - QString pluginName = QString(list.first()); - if (!pluginName.endsWith(':')) continue; + const QString pluginName = list.first().trimmed(); + const PluginVersion version = PluginVersion::tryParse(list.last().trimmed(), {}); - pluginName.chop(1); // remove trailing ':' - PluginVersion version = PluginVersion::tryParse(list.last(), {}); - if (version == PluginVersion()) continue; + if (!version.isValid()) continue; ++numCorrectData; if (isUpdateNeeded(pluginName, version)) { - LogMsg(tr("Plugin %1 is outdated").arg(pluginName), Log::INFO); + LogMsg(tr("Plugin \"%1\" is outdated, updating to version %2").arg(pluginName, version), Log::INFO); updateInfo[pluginName] = version; } }