Merge pull request #11813 from Chocobo1/python

Drop python2 support
This commit is contained in:
Mike Tzou
2020-03-07 10:18:45 +08:00
committed by GitHub
12 changed files with 16 additions and 1247 deletions

View File

@@ -81,7 +81,7 @@ namespace
QPointer<SearchPluginManager> SearchPluginManager::m_instance = nullptr;
SearchPluginManager::SearchPluginManager()
: m_updateUrl(QString("http://searchplugins.qbittorrent.org/%1/engines/").arg(Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3 ? "nova3" : "nova"))
: m_updateUrl(QLatin1String("http://searchplugins.qbittorrent.org/nova3/engines/"))
{
Q_ASSERT(!m_instance); // only one instance is allowed
m_instance = this;
@@ -345,9 +345,7 @@ QString SearchPluginManager::engineLocation()
{
static QString location;
if (location.isEmpty()) {
const QString folder = (Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3)
? "nova3" : "nova";
location = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + folder);
location = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + "nova3");
const QDir locationDir(location);
locationDir.mkpath(locationDir.absolutePath());
@@ -391,8 +389,6 @@ void SearchPluginManager::updateNova()
{
// create nova directory if necessary
const QDir searchDir(engineLocation());
const QString novaFolder = Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3
? "searchengine/nova3" : "searchengine/nova";
QFile packageFile(searchDir.absoluteFilePath("__init__.py"));
packageFile.open(QIODevice::WriteOnly);
@@ -405,9 +401,9 @@ void SearchPluginManager::updateNova()
packageFile2.close();
// Copy search plugin files (if necessary)
const auto updateFile = [&novaFolder](const QString &filename, const bool compareVersion)
const auto updateFile = [](const QString &filename, const bool compareVersion)
{
const QString filePathBundled = ":/" + novaFolder + '/' + filename;
const QString filePathBundled = ":/searchengine/nova3/" + filename;
const QString filePathDisk = QDir(engineLocation()).absoluteFilePath(filename);
if (compareVersion && (getPluginVersion(filePathBundled) <= getPluginVersion(filePathDisk)))
@@ -421,12 +417,8 @@ void SearchPluginManager::updateNova()
updateFile("nova2.py", true);
updateFile("nova2dl.py", true);
updateFile("novaprinter.py", true);
updateFile("sgmllib3.py", false);
updateFile("socks.py", false);
if (Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3)
updateFile("sgmllib3.py", false);
else
updateFile("fix_encoding.py", false);
}
void SearchPluginManager::update()

View File

@@ -240,10 +240,7 @@ bool Utils::ForeignApps::PythonInfo::isValid() const
bool Utils::ForeignApps::PythonInfo::isSupportedVersion() const
{
const int majorVer = version.majorNumber();
return ((majorVer > 3)
|| ((majorVer == 3) && (version >= Version {3, 3, 0}))
|| ((majorVer == 2) && (version >= Version {2, 7, 9})));
return (version >= Version {3, 3, 0});
}
PythonInfo Utils::ForeignApps::pythonInfo()
@@ -251,14 +248,12 @@ PythonInfo Utils::ForeignApps::pythonInfo()
static PythonInfo pyInfo;
if (!pyInfo.isValid()) {
#if defined(Q_OS_UNIX)
// On Unix-Like Systems python2 and python3 should always exist
// On Unix-Like systems python3 should always exist
// https://www.python.org/dev/peps/pep-0394/
if (testPythonInstallation("python3", pyInfo))
return pyInfo;
if (testPythonInstallation("python2", pyInfo))
return pyInfo;
#endif
// Look for "python" in Windows and in UNIX if "python2" and "python3" are
// Look for "python" in Windows and in UNIX if "python3" is
// not detected.
if (testPythonInstallation("python", pyInfo))
return pyInfo;