From fff9bf08fe3659cec91298785d54f7e86e05b7f2 Mon Sep 17 00:00:00 2001 From: "Marcus D. Hanwell" Date: Wed, 2 Sep 2015 10:13:46 -0400 Subject: [PATCH 1/2] Added an error handler to improve debugging Errors were essentially being silently ignored, this isn't loads better, but at least offers clues on the console as to why nothing happened. Added a generic error handler, the other slots seem to ignore the errors, and so should perhaps have the connection removed too. --- avogadro/qtplugins/openbabel/obprocess.cpp | 12 ++++++++++++ avogadro/qtplugins/openbabel/obprocess.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/avogadro/qtplugins/openbabel/obprocess.cpp b/avogadro/qtplugins/openbabel/obprocess.cpp index 4f91dfc95..4da2c6fb0 100644 --- a/avogadro/qtplugins/openbabel/obprocess.cpp +++ b/avogadro/qtplugins/openbabel/obprocess.cpp @@ -91,6 +91,16 @@ void OBProcess::abort() emit aborted(); } +void OBProcess::obError() +{ + qDebug() << "Process encountered an error, and did not execute correctly."; + if (m_process) { + qDebug() << "\tExit code:" << m_process->exitCode(); + qDebug() << "\tExit status:" << m_process->exitStatus(); + qDebug() << "\tExit output:" << m_process->readAll(); + } +} + bool OBProcess::queryReadFormats() { if (!tryLockProcess()) { @@ -345,6 +355,8 @@ void OBProcess::executeObabel(const QStringList &options, if (receiver) { connect(m_process, SIGNAL(finished(int)), receiver, slot); connect(m_process, SIGNAL(error(QProcess::ProcessError)), receiver, slot); + connect(m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(obError())); } // Start process diff --git a/avogadro/qtplugins/openbabel/obprocess.h b/avogadro/qtplugins/openbabel/obprocess.h index e2c412d51..7122dac20 100644 --- a/avogadro/qtplugins/openbabel/obprocess.h +++ b/avogadro/qtplugins/openbabel/obprocess.h @@ -69,6 +69,11 @@ public slots: */ void abort(); + /** + * Called when an error in the process occurs. + */ + void obError(); + signals: /** * Emitted when the abort() method has been called. From 38a9fbbf79134a46803687da4ee84a3b75ebdf87 Mon Sep 17 00:00:00 2001 From: "Marcus D. Hanwell" Date: Wed, 2 Sep 2015 10:39:06 -0400 Subject: [PATCH 2/2] Dynamically search for the data/plugins directories Search more dynamically for the Open Babel data/plugins directories, and warn if we cannot find them. --- avogadro/qtplugins/openbabel/obprocess.cpp | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/avogadro/qtplugins/openbabel/obprocess.cpp b/avogadro/qtplugins/openbabel/obprocess.cpp index 4da2c6fb0..84bd7fd5f 100644 --- a/avogadro/qtplugins/openbabel/obprocess.cpp +++ b/avogadro/qtplugins/openbabel/obprocess.cpp @@ -54,13 +54,28 @@ OBProcess::OBProcess(QObject *parent_) : env.insert("BABEL_DATADIR", QCoreApplication::applicationDirPath() + "/data"); #else - // FIXME: Hardwiring a versioned subdirectory for now. - env.insert("BABEL_DATADIR", - QCoreApplication::applicationDirPath() - + "/../share/openbabel/2.3.2"); - env.insert("BABEL_LIBDIR", - QCoreApplication::applicationDirPath() - + "/../lib/openbabel/2.3.2"); + QDir dir(QCoreApplication::applicationDirPath() + "/../share/openbabel"); + QStringList filters; + filters << "2.*"; + QStringList dirs = dir.entryList(filters); + if (dirs.size() == 1) { + env.insert("BABEL_DATADIR", + QCoreApplication::applicationDirPath() + + "/../share/openbabel/" + dirs[0]); + } + else { + qDebug() << "Error, Open Babel data directory not found."; + } + dir.setPath(QCoreApplication::applicationDirPath() + "/../lib/openbabel"); + dirs = dir.entryList(filters); + if (dirs.size() == 1) { + env.insert("BABEL_LIBDIR", + QCoreApplication::applicationDirPath() + + "/../lib/openbabel/" + dirs[0]); + } + else { + qDebug() << "Error, Open Babel plugins directory not found."; + } #endif m_process->setProcessEnvironment(env); }