diff --git a/avogadro/qtgui/pythonscript.cpp b/avogadro/qtgui/pythonscript.cpp index fa51d26ed8..b075b91b75 100644 --- a/avogadro/qtgui/pythonscript.cpp +++ b/avogadro/qtgui/pythonscript.cpp @@ -100,7 +100,7 @@ QByteArray PythonScript::execute(const QStringList& args, // Write scriptStdin to the process's stdin if (!scriptStdin.isNull()) { - if (!proc.waitForStarted(5000)) { + if (!proc.waitForStarted(5000) && m_debug) { m_errors << tr("Error running script '%1 %2': Timed out waiting for " "start (%3).") .arg(m_pythonInterpreter, @@ -110,7 +110,7 @@ QByteArray PythonScript::execute(const QStringList& args, } qint64 len = proc.write(scriptStdin); - if (len != static_cast(scriptStdin.size())) { + if (len != static_cast(scriptStdin.size()) && m_debug) { m_errors << tr("Error running script '%1 %2': failed to write to stdin " "(len=%3, wrote %4 bytes, QProcess error: %5).") .arg(m_pythonInterpreter) @@ -123,7 +123,7 @@ QByteArray PythonScript::execute(const QStringList& args, proc.closeWriteChannel(); } - if (!proc.waitForFinished(5000)) { + if (!proc.waitForFinished(5000) && m_debug) { m_errors << tr("Error running script '%1 %2': Timed out waiting for " "finish (%3).") .arg(m_pythonInterpreter, realArgs.join(QStringLiteral(" ")), @@ -132,14 +132,17 @@ QByteArray PythonScript::execute(const QStringList& args, } if (proc.exitStatus() != QProcess::NormalExit || proc.exitCode() != 0) { - m_errors << tr("Error running script '%1 %2': Abnormal exit status %3 " - "(%4: %5)\n\nOutput:\n%6") - .arg(m_pythonInterpreter) - .arg(realArgs.join(QStringLiteral(" "))) - .arg(proc.exitCode()) - .arg(processErrorString(proc)) - .arg(proc.errorString()) - .arg(QString(proc.readAll())); + if (m_debug) + m_errors << tr("Error running script '%1 %2': Abnormal exit status %3 " + "(%4: %5)\n\nOutput:\n%6") + .arg(m_pythonInterpreter) + .arg(realArgs.join(QStringLiteral(" "))) + .arg(proc.exitCode()) + .arg(processErrorString(proc)) + .arg(proc.errorString()) + .arg(QString(proc.readAll())); + else + m_errors << tr("Warning '%1'").arg(proc.errorString()); return QByteArray(); } @@ -254,4 +257,4 @@ QString PythonScript::processErrorString(const QProcess& proc) const return result; } -} // namespace Avogadro +} // namespace Avogadro::QtGui diff --git a/avogadro/qtgui/scriptloader.cpp b/avogadro/qtgui/scriptloader.cpp index 203b55becf..f77e918792 100644 --- a/avogadro/qtgui/scriptloader.cpp +++ b/avogadro/qtgui/scriptloader.cpp @@ -27,9 +27,7 @@ namespace Avogadro::QtGui { -ScriptLoader::ScriptLoader(QObject* parent_) - : QObject(parent_) -{} +ScriptLoader::ScriptLoader(QObject* parent_) : QObject(parent_) {} ScriptLoader::~ScriptLoader() {} @@ -40,9 +38,7 @@ bool ScriptLoader::queryProgramName(const QString& scriptFilePath, displayName = gen.displayName(); if (gen.hasErrors()) { displayName.clear(); - qWarning() << "ScriptLoader::queryProgramName: Unable to retrieve program " - "name for" - << scriptFilePath << ";" << gen.errorList().join("\n\n"); + qWarning() << tr("Cannot load script %1").arg(scriptFilePath); return false; } return true; @@ -69,7 +65,7 @@ QMap ScriptLoader::scriptList(const QString& type) // build up a list of possible files, then we check if they're real scripts QStringList fileList; foreach (const QString& dirStr, dirs) { - qDebug() << "Checking for " << type << " scripts in" << dirStr; + qDebug() << tr("Checking for %1 scripts in path %2").arg(type).arg(dirStr); QDir dir(dirStr); if (dir.exists() && dir.isReadable()) { foreach ( @@ -97,7 +93,7 @@ QMap ScriptLoader::scriptList(const QString& type) if (commands.type() == QJsonValue::Array) { // check if "command.*" exists as a file QJsonArray list = commands.toArray(); - for (auto && i : list) { + for (auto&& i : list) { QJsonValue command = i.toObject()["command"]; QString name = command.toString(); if (name.isEmpty() || name.isNull()) @@ -153,4 +149,4 @@ QMap ScriptLoader::scriptList(const QString& type) return scriptList; } -} // namespace Avogadro +} // namespace Avogadro::QtGui diff --git a/avogadro/qtplugins/scriptcharges/chargeScripts/antechamber.py b/avogadro/qtplugins/scriptcharges/chargeScripts/antechamber.py index 4e3b3fda61..f902abc8a3 100644 --- a/avogadro/qtplugins/scriptcharges/chargeScripts/antechamber.py +++ b/avogadro/qtplugins/scriptcharges/chargeScripts/antechamber.py @@ -148,7 +148,7 @@ def potential(): if name: print(name) else: - raise RuntimeError("antechamber is unavailable") + sys.exit("antechamber is unavailable") elif args["charges"]: print(charges()) elif args["potential"]: diff --git a/avogadro/qtplugins/scriptcharges/chargeScripts/xtb.py b/avogadro/qtplugins/scriptcharges/chargeScripts/xtb.py index 193b58b40e..5f6f181939 100644 --- a/avogadro/qtplugins/scriptcharges/chargeScripts/xtb.py +++ b/avogadro/qtplugins/scriptcharges/chargeScripts/xtb.py @@ -97,7 +97,7 @@ def potential(): if name: print(name) else: - raise RuntimeError("xtb is unavailable") + sys.exit("xtb is unavailable") elif args["charges"]: print(charges()) elif args["potential"]: