Drop python2 support.

This commit is contained in:
sledgehammer999
2017-06-22 18:52:13 +03:00
parent a77e1c9f36
commit 7d030b4cd9
11 changed files with 22 additions and 1231 deletions

View File

@@ -63,7 +63,7 @@ static inline void removePythonScriptIfExists(const QString &scriptPath)
const QHash<QString, QString> SearchEngine::m_categoryNames = SearchEngine::initializeCategoryNames();
SearchEngine::SearchEngine()
: m_updateUrl(QString("http://searchplugins.qbittorrent.org/%1/engines/").arg(Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova"))
: m_updateUrl(QString("http://searchplugins.qbittorrent.org/nova%1/engines/").arg(Utils::Misc::pythonVersion()))
, m_searchStopped(false)
{
updateNova();
@@ -337,10 +337,8 @@ QString SearchEngine::pluginsLocation()
QString SearchEngine::engineLocation()
{
QString folder = "nova";
if (Utils::Misc::pythonVersion() >= 3)
folder = "nova3";
const QString location = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + folder);
const QString location = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data)
+ QString("nova%1").arg(Utils::Misc::pythonVersion()));
QDir locationDir(location);
if (!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
@@ -414,7 +412,7 @@ void SearchEngine::updateNova()
// create nova directory if necessary
QDir searchDir(engineLocation());
QString novaFolder = Utils::Misc::pythonVersion() >= 3 ? "searchengine/nova3" : "searchengine/nova";
QString novaFolder = QString("searchengine/nova%1").arg(Utils::Misc::pythonVersion());
QFile packageFile(searchDir.absoluteFilePath("__init__.py"));
packageFile.open(QIODevice::WriteOnly | QIODevice::Text);
packageFile.close();
@@ -458,16 +456,10 @@ void SearchEngine::updateNova()
removePythonScriptIfExists(filePath);
QFile::copy(":/" + novaFolder + "/socks.py", filePath);
if (novaFolder.endsWith("nova")) {
filePath = searchDir.absoluteFilePath("fix_encoding.py");
removePythonScriptIfExists(filePath);
QFile::copy(":/" + novaFolder + "/fix_encoding.py", filePath);
}
else if (novaFolder.endsWith("nova3")) {
filePath = searchDir.absoluteFilePath("sgmllib3.py");
removePythonScriptIfExists(filePath);
QFile::copy(":/" + novaFolder + "/sgmllib3.py", filePath);
}
filePath = searchDir.absoluteFilePath("sgmllib3.py");
removePythonScriptIfExists(filePath);
QFile::copy(":/" + novaFolder + "/sgmllib3.py", filePath);
QDir destDir(pluginsLocation());
Utils::Fs::removeDirRecursive(destDir.absoluteFilePath("__pycache__"));

View File

@@ -238,14 +238,11 @@ QPoint Utils::Misc::screenCenter(const QWidget *w)
int Utils::Misc::pythonVersion()
{
static int version = -1;
if (version < 0) {
if (version != 3) {
QString versionComplete = pythonVersionComplete().trimmed();
QStringList splitted = versionComplete.split('.');
if (splitted.size() > 1) {
int highVer = splitted.at(0).toInt();
if ((highVer == 2) || (highVer == 3))
version = highVer;
}
if (splitted.size() > 1)
version = splitted.at(0).toInt();
}
return version;
}
@@ -268,11 +265,6 @@ QString Utils::Misc::pythonExecutable()
executable = "python3";
return executable;
}
pythonProc.start("python2", QStringList() << "--version", QIODevice::ReadOnly);
if (pythonProc.waitForFinished() && (pythonProc.exitCode() == 0)) {
executable = "python2";
return executable;
}
#endif
// Look for "python" in Windows and in UNIX if "python2" and "python3" are
// not detected.