mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-22 14:23:35 -07:00
Use python3 and python2 instead of python on Linux
Prefer python3 over python2 when both are available. Both python2 and python3 should always exists. More info at: http://legacy.python.org/dev/peps/pep-0394/ Conflicts: src/core/utils/misc.h src/searchengine/supportedengines.h
This commit is contained in:
parent
5c9ce2952b
commit
7e63908977
4 changed files with 41 additions and 3 deletions
|
@ -271,6 +271,26 @@ int 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;
|
||||||
|
@ -283,10 +303,26 @@ int misc::pythonVersion()
|
||||||
version = 3;
|
version = 3;
|
||||||
else
|
else
|
||||||
version = 2;
|
version = 2;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString 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
|
||||||
|
|
|
@ -82,6 +82,7 @@ namespace misc
|
||||||
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
|
||||||
|
|
|
@ -235,7 +235,7 @@ void SearchEngine::on_search_button_clicked() {
|
||||||
//on change le texte du label courrant
|
//on change le texte du label courrant
|
||||||
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(misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
searchTimeout->start(180000); // 3min
|
searchTimeout->start(180000); // 3min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,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(misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "fs_utils.h"
|
#include "fs_utils.h"
|
||||||
|
#include "misc.h"
|
||||||
#include "preferences.h"
|
#include "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 << fsutils::toNativePath(fsutils::searchEngineLocation()+"/nova2.py");
|
params << fsutils::toNativePath(fsutils::searchEngineLocation()+"/nova2.py");
|
||||||
params << "--capabilities";
|
params << "--capabilities";
|
||||||
nova.start("python", params, QIODevice::ReadOnly);
|
nova.start(misc::pythonExecutable(), params, QIODevice::ReadOnly);
|
||||||
nova.waitForStarted();
|
nova.waitForStarted();
|
||||||
nova.waitForFinished();
|
nova.waitForFinished();
|
||||||
QString capabilities = QString(nova.readAll());
|
QString capabilities = QString(nova.readAll());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue