mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
commit
0e62a52e59
@ -226,74 +226,56 @@ QPoint Utils::Misc::screenCenter(QWidget *win)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects the version of python by calling
|
* Detects the python version.
|
||||||
* "python --version" and parsing the output.
|
|
||||||
*/
|
*/
|
||||||
int Utils::Misc::pythonVersion()
|
int Utils::Misc::pythonVersion()
|
||||||
{
|
{
|
||||||
static int version = -1;
|
static int version = -1;
|
||||||
if (version < 0) {
|
if (version < 0) {
|
||||||
QProcess python_proc;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects the python executable by calling "python --version".
|
||||||
|
*/
|
||||||
|
QString Utils::Misc::pythonExecutable()
|
||||||
|
{
|
||||||
|
static QString executable;
|
||||||
|
if (executable.isEmpty()) {
|
||||||
|
QProcess pythonProc;
|
||||||
#if defined(Q_OS_UNIX)
|
#if defined(Q_OS_UNIX)
|
||||||
/*
|
/*
|
||||||
* On Unix-Like Systems python2 and python3 should always exist
|
* On Unix-Like Systems python2 and python3 should always exist
|
||||||
* http://legacy.python.org/dev/peps/pep-0394/
|
* http://legacy.python.org/dev/peps/pep-0394/
|
||||||
*/
|
*/
|
||||||
python_proc.start("python3", QStringList() << "--version", QIODevice::ReadOnly);
|
pythonProc.start("python3", QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
if (python_proc.waitForFinished()) {
|
if (pythonProc.waitForFinished() && pythonProc.exitCode() == 0) {
|
||||||
if (python_proc.exitCode() == 0) {
|
executable = "python3";
|
||||||
QByteArray output = python_proc.readAllStandardOutput();
|
return executable;
|
||||||
if (output.isEmpty())
|
|
||||||
output = python_proc.readAllStandardError();
|
|
||||||
const QByteArray version_str = output.split(' ').last();
|
|
||||||
Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python version: %1").arg(QString(version_str)), Log::INFO);
|
|
||||||
version = 3;
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
python_proc.start("python2", QStringList() << "--version", QIODevice::ReadOnly);
|
pythonProc.start("python2", QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
if (python_proc.waitForFinished()) {
|
if (pythonProc.waitForFinished() && pythonProc.exitCode() == 0) {
|
||||||
if (python_proc.exitCode() == 0) {
|
executable = "python2";
|
||||||
QByteArray output = python_proc.readAllStandardOutput();
|
return executable;
|
||||||
if (output.isEmpty())
|
|
||||||
output = python_proc.readAllStandardError();
|
|
||||||
const QByteArray version_str = output.split(' ').last();
|
|
||||||
Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python version: %1").arg(QString(version_str)), Log::INFO);
|
|
||||||
version = 2;
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
python_proc.start("python", QStringList() << "--version", QIODevice::ReadOnly);
|
// Look for "python" in Windows and in UNIX if "python2" and "python3" are
|
||||||
if (!python_proc.waitForFinished()) return -1;
|
// not detected.
|
||||||
if (python_proc.exitCode() < 0) return -1;
|
pythonProc.start("python", QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
QByteArray output = python_proc.readAllStandardOutput();
|
if (pythonProc.waitForFinished() && pythonProc.exitCode() == 0)
|
||||||
if (output.isEmpty())
|
executable = "python";
|
||||||
output = python_proc.readAllStandardError();
|
|
||||||
const QByteArray version_str = output.split(' ').last();
|
|
||||||
Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python version: %1").arg(QString(version_str)), Log::INFO);
|
|
||||||
if (version_str.startsWith("3."))
|
|
||||||
version = 3;
|
|
||||||
else
|
else
|
||||||
version = 2;
|
Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python not detected"), Log::INFO);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return version;
|
return executable;
|
||||||
}
|
|
||||||
|
|
||||||
QString Utils::Misc::pythonExecutable()
|
|
||||||
{
|
|
||||||
#if defined(Q_OS_UNIX)
|
|
||||||
/*
|
|
||||||
* 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";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -303,22 +285,20 @@ QString Utils::Misc::pythonExecutable()
|
|||||||
*/
|
*/
|
||||||
QString Utils::Misc::pythonVersionComplete() {
|
QString Utils::Misc::pythonVersionComplete() {
|
||||||
static QString version;
|
static QString version;
|
||||||
|
|
||||||
if (version.isEmpty()) {
|
if (version.isEmpty()) {
|
||||||
if (pythonVersion() < 0)
|
if (pythonExecutable().isEmpty())
|
||||||
return QString();
|
return version;
|
||||||
|
QProcess pythonProc;
|
||||||
QProcess python_proc;
|
pythonProc.start(pythonExecutable(), QStringList() << "--version", QIODevice::ReadOnly);
|
||||||
python_proc.start(pythonExecutable(), QStringList() << "--version", QIODevice::ReadOnly);
|
if (pythonProc.waitForFinished() && pythonProc.exitCode() == 0) {
|
||||||
if (!python_proc.waitForFinished()) return QString();
|
QByteArray output = pythonProc.readAllStandardOutput();
|
||||||
if (python_proc.exitCode() < 0) return QString();
|
if (output.isEmpty())
|
||||||
QByteArray output = python_proc.readAllStandardOutput();
|
output = pythonProc.readAllStandardError();
|
||||||
if (output.isEmpty())
|
const QByteArray versionStr = output.split(' ').last();
|
||||||
output = python_proc.readAllStandardError();
|
version = versionStr.trimmed();
|
||||||
const QByteArray version_str = output.split(' ').last();
|
Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python version: %1").arg(version), Log::INFO);
|
||||||
version = version_str;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1383,36 +1383,13 @@ void MainWindow::on_actionSearch_engine_triggered()
|
|||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
if (pythonVersion == 2) {
|
if ((pythonVersion == 2) || (pythonVersion == 3)) {
|
||||||
// Check if python 2.7.x or later
|
// Check python minimum requirement: 2.7.0/3.3.0
|
||||||
QString version = Utils::Misc::pythonVersionComplete().trimmed();
|
QString version = Utils::Misc::pythonVersionComplete();
|
||||||
QStringList splitted = version.split('.');
|
QStringList splitted = version.split('.');
|
||||||
if (splitted.size() > 1) {
|
if (splitted.size() > 1) {
|
||||||
int middleVer = splitted.at(1).toInt();
|
int middleVer = splitted.at(1).toInt();
|
||||||
if (middleVer < 7) {
|
if ((pythonVersion == 2 && middleVer < 7) || (pythonVersion == 3 && middleVer < 3)) {
|
||||||
QMessageBox::information(this, tr("Old Python Interpreter"), tr("Your Python version is %1, which is too old. You need at least version 2.7.0 for python2 or 3.3.0 for python3.").arg(version));
|
|
||||||
actionSearch_engine->setChecked(false);
|
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QMessageBox::information(this, tr("Undetermined Python version"), tr("Couldn't decode your Python version: %1").arg(version));
|
|
||||||
actionSearch_engine->setChecked(false);
|
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (pythonVersion == 3) {
|
|
||||||
// Check if python 3.3.x or later
|
|
||||||
QString version = Utils::Misc::pythonVersionComplete().trimmed();
|
|
||||||
QStringList splitted = version.split('.');
|
|
||||||
if (splitted.size() > 1) {
|
|
||||||
int middleVer = splitted.at(1).toInt();
|
|
||||||
if (middleVer < 3) {
|
|
||||||
QMessageBox::information(this, tr("Old Python Interpreter"), tr("Your Python version %1 is outdated. Please upgrade to latest version for search engines to work. Minimum requirement: 2.7.0/3.3.0.").arg(version));
|
QMessageBox::information(this, tr("Old Python Interpreter"), tr("Your Python version %1 is outdated. Please upgrade to latest version for search engines to work. Minimum requirement: 2.7.0/3.3.0.").arg(version));
|
||||||
actionSearch_engine->setChecked(false);
|
actionSearch_engine->setChecked(false);
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
Preferences::instance()->setSearchEnabled(false);
|
||||||
@ -1429,9 +1406,6 @@ void MainWindow::on_actionSearch_engine_triggered()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
res = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
has_python = true;
|
has_python = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user