Skip to content

Commit

Permalink
Give better warnings when scripts do not load
Browse files Browse the repository at this point in the history
Fix #1323 - now indicates Cannot load script /path/to/antechamber.py
Also enables i18n of script loader strings

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Sep 11, 2023
1 parent 22665df commit 8579443
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
27 changes: 15 additions & 12 deletions avogadro/qtgui/pythonscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -110,7 +110,7 @@ QByteArray PythonScript::execute(const QStringList& args,
}

qint64 len = proc.write(scriptStdin);
if (len != static_cast<qint64>(scriptStdin.size())) {
if (len != static_cast<qint64>(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)
Expand All @@ -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(" ")),
Expand All @@ -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();
}

Expand Down Expand Up @@ -254,4 +257,4 @@ QString PythonScript::processErrorString(const QProcess& proc) const
return result;
}

} // namespace Avogadro
} // namespace Avogadro::QtGui
7 changes: 3 additions & 4 deletions avogadro/qtgui/scriptloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ 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;
Expand All @@ -69,7 +68,7 @@ QMap<QString, QString> 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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion avogadro/qtplugins/scriptcharges/chargeScripts/xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down

0 comments on commit 8579443

Please sign in to comment.