Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give better warnings when scripts do not load #1336

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Give better warnings when scripts do not load
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
commit 85794435e1cc58b67406967facb3fdf0e4fba00c
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