Changes in src/Python/PythonScripting.cpp [2cf12a:57388c9]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Python/PythonScripting.cpp
r2cf12a r57388c9 39 39 #include "CodePatterns/MemDebug.hpp" 40 40 41 bool executePythonScript File(const boost::filesystem::path &pythonfilename)41 bool executePythonScript(const std::string &pythonfilename_string) 42 42 { 43 boost::filesystem::path pythonfilename(pythonfilename_string); 43 44 if (exists(pythonfilename)) { 44 45 // parse in and execute the local and global config.py … … 60 61 std::string pythonscript( std::istreambuf_iterator<char>(pythonfile), 61 62 (std::istreambuf_iterator<char>()) ); 62 std::string enveloped_script("print \"BEGIN of "+pythonfilename .string()+":\"\n");63 std::string enveloped_script("print \"BEGIN of "+pythonfilename_string+":\"\n"); 63 64 enveloped_script += pythonscript; 64 enveloped_script += std::string("print \"END of "+pythonfilename .string()+":\"\n");65 enveloped_script += std::string("print \"END of "+pythonfilename_string+":\"\n"); 65 66 66 67 boost::python::handle<> ignored(( PyRun_String( enveloped_script.c_str(), … … 77 78 return false; 78 79 } 79 80 bool executePythonScript(const std::string &python_string, const std::string &python_scripttitle)81 {82 try {83 PyImport_AppendInittab( "pyMoleCuilder", &initpyMoleCuilder );84 85 Py_Initialize();86 87 boost::python::object main_module((88 boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("__main__")))));89 90 boost::python::object main_namespace = main_module.attr("__dict__");91 92 boost::python::object molecuilder_module( (boost::python::handle<>(PyImport_ImportModule("pyMoleCuilder"))) );93 main_namespace["pyMoleCuilder"] = molecuilder_module;94 95 std::string enveloped_script("print \"BEGIN of "+python_scripttitle+":\"\n");96 enveloped_script += python_string+std::string("\n");97 enveloped_script += std::string("print \"END of "+python_scripttitle+":\"\n");98 99 boost::python::handle<> ignored(( PyRun_String( enveloped_script.c_str(),100 Py_file_input,101 main_namespace.ptr(),102 main_namespace.ptr() ) ));103 104 } catch( boost::python::error_already_set ) {105 PyErr_Print();106 return false;107 }108 return true;109 }
Note:
See TracChangeset
for help on using the changeset viewer.