| 1659 | } |
| 1660 | |
| 1661 | bool |
| 1662 | AppManager::findAndRunScriptFile(const QString& path, |
| 1663 | const QStringList& files, |
| 1664 | const QString& script) |
| 1665 | { |
| 1666 | #ifdef NATRON_RUN_WITHOUT_PYTHON |
| 1667 | |
| 1668 | return false; |
| 1669 | #endif |
| 1670 | for (QStringList::const_iterator it = files.begin(); it != files.end(); ++it) { |
| 1671 | if (*it == script) { |
| 1672 | QString absolutePath = path + *it; |
| 1673 | QFile file(absolutePath); |
| 1674 | if ( file.open(QIODevice::ReadOnly) ) { |
| 1675 | QTextStream ts(&file); |
| 1676 | QString content = ts.readAll(); |
| 1677 | PyRun_SimpleString( content.toStdString().c_str() ); |
| 1678 | |
| 1679 | |
| 1680 | PyObject* mainModule = NATRON_PYTHON_NAMESPACE::getMainModule(); |
| 1681 | std::string error, output; |
| 1682 | |
| 1683 | ///Gui session, do stdout, stderr redirection |
| 1684 | PyObject *errCatcher = 0; |
| 1685 | PyObject *outCatcher = 0; |
| 1686 | |
| 1687 | if ( PyObject_HasAttrString(mainModule, "catchErr") ) { |
| 1688 | errCatcher = PyObject_GetAttrString(mainModule, "catchErr"); //get our catchOutErr created above, new ref |
| 1689 | } |
| 1690 | |
| 1691 | if ( PyObject_HasAttrString(mainModule, "catchOut") ) { |
| 1692 | outCatcher = PyObject_GetAttrString(mainModule, "catchOut"); //get our catchOutErr created above, new ref |
| 1693 | } |
| 1694 | |
| 1695 | PyErr_Print(); //make python print any errors |
| 1696 | |
| 1697 | PyObject *errorObj = 0; |
| 1698 | if (errCatcher) { |
| 1699 | errorObj = PyObject_GetAttrString(errCatcher, "value"); //get the stderr from our catchErr object, new ref |
| 1700 | assert(errorObj); |
| 1701 | |
| 1702 | error = NATRON_PYTHON_NAMESPACE::PyStringToStdString(errorObj); |
| 1703 | PyObject* unicode = PyUnicode_FromString(""); |
| 1704 | PyObject_SetAttrString(errCatcher, "value", unicode); |
| 1705 | Py_DECREF(errorObj); |
| 1706 | Py_DECREF(errCatcher); |
| 1707 | } |
| 1708 | PyObject *outObj = 0; |
| 1709 | if (outCatcher) { |
| 1710 | outObj = PyObject_GetAttrString(outCatcher, "value"); //get the stdout from our catchOut object, new ref |
| 1711 | assert(outObj); |
| 1712 | output = NATRON_PYTHON_NAMESPACE::PyStringToStdString(outObj); |
| 1713 | PyObject* unicode = PyUnicode_FromString(""); |
| 1714 | PyObject_SetAttrString(outCatcher, "value", unicode); |
| 1715 | Py_DECREF(outObj); |
| 1716 | Py_DECREF(outCatcher); |
| 1717 | } |
| 1718 |
nothing calls this directly
no test coverage detected