MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / findAndRunScriptFile

Method findAndRunScriptFile

Engine/AppManager.cpp:1575–1661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1573}
1574
1575bool
1576AppManager::findAndRunScriptFile(const QString& path,
1577 const QStringList& files,
1578 const QString& script)
1579{
1580#ifdef NATRON_RUN_WITHOUT_PYTHON
1581
1582 return false;
1583#endif
1584 for (QStringList::const_iterator it = files.begin(); it != files.end(); ++it) {
1585 if (*it == script) {
1586 QString absolutePath = path + *it;
1587 QFile file(absolutePath);
1588 if ( file.open(QIODevice::ReadOnly) ) {
1589 QTextStream ts(&file);
1590 QString content = ts.readAll();
1591 PythonGILLocker pgl;
1592
1593 PyRun_SimpleString( content.toStdString().c_str() );
1594
1595
1596 PyObject* mainModule = NATRON_PYTHON_NAMESPACE::getMainModule();
1597 std::string error, output;
1598
1599 ///Gui session, do stdout, stderr redirection
1600 PyObject *errCatcher = 0;
1601 PyObject *outCatcher = 0;
1602
1603 if ( PyObject_HasAttrString(mainModule, "catchErr") ) {
1604 errCatcher = PyObject_GetAttrString(mainModule, "catchErr"); //get our catchOutErr created above, new ref
1605 }
1606
1607 if ( PyObject_HasAttrString(mainModule, "catchOut") ) {
1608 outCatcher = PyObject_GetAttrString(mainModule, "catchOut"); //get our catchOutErr created above, new ref
1609 }
1610
1611 PyErr_Print(); //make python print any errors
1612
1613 PyObject *errorObj = 0;
1614 if (errCatcher) {
1615 errorObj = PyObject_GetAttrString(errCatcher, "value"); //get the stderr from our catchErr object, new ref
1616 assert(errorObj);
1617
1618 error = NATRON_PYTHON_NAMESPACE::PyStringToStdString(errorObj);
1619 PyObject* unicode = PyUnicode_FromString("");
1620 PyObject_SetAttrString(errCatcher, "value", unicode);
1621 Py_DECREF(errorObj);
1622 Py_DECREF(errCatcher);
1623 }
1624 PyObject *outObj = 0;
1625 if (outCatcher) {
1626 outObj = PyObject_GetAttrString(outCatcher, "value"); //get the stdout from our catchOut object, new ref
1627 assert(outObj);
1628 output = NATRON_PYTHON_NAMESPACE::PyStringToStdString(outObj);
1629 PyObject* unicode = PyUnicode_FromString("");
1630 PyObject_SetAttrString(outCatcher, "value", unicode);
1631 Py_DECREF(outObj);
1632 Py_DECREF(outCatcher);

Callers

nothing calls this directly

Calls 10

PyStringToStdStringFunction · 0.85
toStdStringMethod · 0.80
emptyMethod · 0.80
appendMethod · 0.80
getTopLevelInstanceMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
openMethod · 0.45
appendToScriptEditorMethod · 0.45

Tested by

no test coverage detected