mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06:00
Improve checks for python. Print python version and path to log.
Conflicts: src/core/misc.cpp src/core/utils/misc.h src/gui/mainwindow.cpp
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#include "core/unicodestrings.h"
|
||||
#include "core/logger.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -279,6 +280,11 @@ int misc::pythonVersion()
|
||||
python_proc.start("python3", QStringList() << "--version", QIODevice::ReadOnly);
|
||||
if (python_proc.waitForFinished()) {
|
||||
if (python_proc.exitCode() == 0) {
|
||||
QByteArray output = python_proc.readAllStandardOutput();
|
||||
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;
|
||||
}
|
||||
@@ -286,6 +292,11 @@ int misc::pythonVersion()
|
||||
python_proc.start("python2", QStringList() << "--version", QIODevice::ReadOnly);
|
||||
if (python_proc.waitForFinished()) {
|
||||
if (python_proc.exitCode() == 0) {
|
||||
QByteArray output = python_proc.readAllStandardOutput();
|
||||
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;
|
||||
}
|
||||
@@ -298,7 +309,7 @@ int misc::pythonVersion()
|
||||
if (output.isEmpty())
|
||||
output = python_proc.readAllStandardError();
|
||||
const QByteArray version_str = output.split(' ').last();
|
||||
qDebug() << "Python version is:" << version_str.trimmed();
|
||||
Logger::instance()->addMessage(QCoreApplication::translate("misc", "Python version: %1").arg(QString(version_str)), Log::INFO);
|
||||
if (version_str.startsWith("3."))
|
||||
version = 3;
|
||||
else
|
||||
@@ -323,6 +334,32 @@ QString misc::pythonExecutable()
|
||||
return "python";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the complete python version
|
||||
* eg 2.7.9
|
||||
* Make sure to have setup python first
|
||||
*/
|
||||
QString misc::pythonVersionComplete() {
|
||||
static QString version;
|
||||
|
||||
if (version.isEmpty()) {
|
||||
if (pythonVersion() < 0)
|
||||
return QString();
|
||||
|
||||
QProcess python_proc;
|
||||
python_proc.start(pythonExecutable(), QStringList() << "--version", QIODevice::ReadOnly);
|
||||
if (!python_proc.waitForFinished()) return QString();
|
||||
if (python_proc.exitCode() < 0) return QString();
|
||||
QByteArray output = python_proc.readAllStandardOutput();
|
||||
if (output.isEmpty())
|
||||
output = python_proc.readAllStandardError();
|
||||
const QByteArray version_str = output.split(' ').last();
|
||||
version = version_str;
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
// return best userfriendly storage unit (B, KiB, MiB, GiB, TiB)
|
||||
// use Binary prefix standards from IEC 60027-2
|
||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||
|
||||
Reference in New Issue
Block a user