mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 11:24:15 +00:00
Merge pull request #2624 from pmzqla/python
Prefer python3 over python2
This commit is contained in:
commit
d6af4683bb
@ -1763,11 +1763,12 @@ QString Preferences::getPythonPath()
|
|||||||
return path;
|
return path;
|
||||||
|
|
||||||
// Fallback: Detect python from default locations
|
// Fallback: Detect python from default locations
|
||||||
QStringList supported_versions;
|
const QStringList dirs = QDir("C:/").entryList(QStringList("Python*"), QDir::Dirs, QDir::Name | QDir::Reversed);
|
||||||
supported_versions << "34" << "33" << "32" << "31" << "30" << "27" << "26" << "25";
|
foreach (const QString &dir, dirs) {
|
||||||
foreach (const QString &v, supported_versions)
|
const QString path("C:/" + dir + "/python.exe");
|
||||||
if (QFile::exists("C:/Python" + v + "/python.exe"))
|
if (QFile::exists(path))
|
||||||
return "C:/Python" + v;
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
@ -233,6 +233,26 @@ int Utils::Misc::pythonVersion()
|
|||||||
static int version = -1;
|
static int version = -1;
|
||||||
if (version < 0) {
|
if (version < 0) {
|
||||||
QProcess python_proc;
|
QProcess python_proc;
|
||||||
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||||
|
/*
|
||||||
|
* On Unix-Like Systems python2 and python3 should always exist
|
||||||
|
* http://legacy.python.org/dev/peps/pep-0394/
|
||||||
|
*/
|
||||||
|
python_proc.start("python3", QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
|
if (python_proc.waitForFinished()) {
|
||||||
|
if (python_proc.exitCode() == 0) {
|
||||||
|
version = 3;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
python_proc.start("python2", QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
|
if (python_proc.waitForFinished()) {
|
||||||
|
if (python_proc.exitCode() == 0) {
|
||||||
|
version = 2;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
python_proc.start("python", QStringList() << "--version", QIODevice::ReadOnly);
|
python_proc.start("python", QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
if (!python_proc.waitForFinished()) return -1;
|
if (!python_proc.waitForFinished()) return -1;
|
||||||
if (python_proc.exitCode() < 0) return -1;
|
if (python_proc.exitCode() < 0) return -1;
|
||||||
@ -245,10 +265,26 @@ int Utils::Misc::pythonVersion()
|
|||||||
version = 3;
|
version = 3;
|
||||||
else
|
else
|
||||||
version = 2;
|
version = 2;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Utils::Misc::pythonExecutable()
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||||
|
/*
|
||||||
|
* On Unix-Like Systems python2 and python3 should always exist
|
||||||
|
* http://legacy.python.org/dev/peps/pep-0394/
|
||||||
|
*/
|
||||||
|
if (pythonVersion() == 3)
|
||||||
|
return "python3";
|
||||||
|
if (pythonVersion() == 2)
|
||||||
|
return "python2";
|
||||||
|
#endif
|
||||||
|
return "python";
|
||||||
|
}
|
||||||
|
|
||||||
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
||||||
// use Binary prefix standards from IEC 60027-2
|
// use Binary prefix standards from IEC 60027-2
|
||||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||||
|
@ -56,6 +56,7 @@ namespace Utils
|
|||||||
QPoint screenCenter(QWidget *win);
|
QPoint screenCenter(QWidget *win);
|
||||||
#endif
|
#endif
|
||||||
int pythonVersion();
|
int pythonVersion();
|
||||||
|
QString pythonExecutable();
|
||||||
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
||||||
// use Binary prefix standards from IEC 60027-2
|
// use Binary prefix standards from IEC 60027-2
|
||||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||||
|
@ -1380,7 +1380,7 @@ void MainWindow::on_actionSearch_engine_triggered()
|
|||||||
has_python = true;
|
has_python = true;
|
||||||
}
|
}
|
||||||
else if (QMessageBox::question(this, tr("Missing Python Interpreter"),
|
else if (QMessageBox::question(this, tr("Missing Python Interpreter"),
|
||||||
tr("Python 2.x is required to use the search engine but it does not seem to be installed.\nDo you want to install it now?"),
|
tr("Python is required to use the search engine but it does not seem to be installed.\nDo you want to install it now?"),
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
|
||||||
// Download and Install Python
|
// Download and Install Python
|
||||||
installPython();
|
installPython();
|
||||||
@ -1570,7 +1570,7 @@ void MainWindow::installPython()
|
|||||||
{
|
{
|
||||||
setCursor(QCursor(Qt::WaitCursor));
|
setCursor(QCursor(Qt::WaitCursor));
|
||||||
// Download python
|
// Download python
|
||||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl("http://python.org/ftp/python/2.7.3/python-2.7.3.msi");
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl("https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi");
|
||||||
connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(pythonDownloadSuccess(QString, QString)));
|
connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(pythonDownloadSuccess(QString, QString)));
|
||||||
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(pythonDownloadFailure(QString, QString)));
|
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(pythonDownloadFailure(QString, QString)));
|
||||||
}
|
}
|
||||||
|
@ -182,6 +182,11 @@ void SearchEngine::giveFocusToSearchInput() {
|
|||||||
|
|
||||||
// Function called when we click on search button
|
// Function called when we click on search button
|
||||||
void SearchEngine::on_search_button_clicked() {
|
void SearchEngine::on_search_button_clicked() {
|
||||||
|
if (Utils::Misc::pythonVersion() < 0) {
|
||||||
|
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (searchProcess->state() != QProcess::NotRunning) {
|
if (searchProcess->state() != QProcess::NotRunning) {
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
searchProcess->kill();
|
searchProcess->kill();
|
||||||
@ -236,7 +241,7 @@ void SearchEngine::on_search_button_clicked() {
|
|||||||
// Changing the text of the current label
|
// Changing the text of the current label
|
||||||
currentSearchTab->getCurrentLabel()->setText(tr("Results")+" <i>(0)</i>:");
|
currentSearchTab->getCurrentLabel()->setText(tr("Results")+" <i>(0)</i>:");
|
||||||
// Launch search
|
// Launch search
|
||||||
searchProcess->start("python", params, QIODevice::ReadOnly);
|
searchProcess->start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
searchTimeout->start(180000); // 3min
|
searchTimeout->start(180000); // 3min
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +281,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) {
|
|||||||
params << engine_url;
|
params << engine_url;
|
||||||
params << torrent_url;
|
params << torrent_url;
|
||||||
// Launch search
|
// Launch search
|
||||||
downloadProcess->start("python", params, QIODevice::ReadOnly);
|
downloadProcess->start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "core/utils/fs.h"
|
#include "core/utils/fs.h"
|
||||||
|
#include "core/utils/misc.h"
|
||||||
#include "core/preferences.h"
|
#include "core/preferences.h"
|
||||||
|
|
||||||
class SearchCategories: public QObject, public QHash<QString, QString> {
|
class SearchCategories: public QObject, public QHash<QString, QString> {
|
||||||
@ -150,7 +151,7 @@ public slots:
|
|||||||
QStringList params;
|
QStringList params;
|
||||||
params << Utils::Fs::toNativePath(Utils::Fs::searchEngineLocation()+"/nova2.py");
|
params << Utils::Fs::toNativePath(Utils::Fs::searchEngineLocation()+"/nova2.py");
|
||||||
params << "--capabilities";
|
params << "--capabilities";
|
||||||
nova.start("python", params, QIODevice::ReadOnly);
|
nova.start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
nova.waitForStarted();
|
nova.waitForStarted();
|
||||||
nova.waitForFinished();
|
nova.waitForFinished();
|
||||||
QString capabilities = QString(nova.readAll());
|
QString capabilities = QString(nova.readAll());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user