Changes in src/Python/PythonScripting.cpp [57388c9:2cf12a]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Python/PythonScripting.cpp
r57388c9 r2cf12a 39 39 #include "CodePatterns/MemDebug.hpp" 40 40 41 bool executePythonScript (const std::string &pythonfilename_string)41 bool executePythonScriptFile(const boost::filesystem::path &pythonfilename) 42 42 { 43 boost::filesystem::path pythonfilename(pythonfilename_string);44 43 if (exists(pythonfilename)) { 45 44 // parse in and execute the local and global config.py … … 61 60 std::string pythonscript( std::istreambuf_iterator<char>(pythonfile), 62 61 (std::istreambuf_iterator<char>()) ); 63 std::string enveloped_script("print \"BEGIN of "+pythonfilename _string+":\"\n");62 std::string enveloped_script("print \"BEGIN of "+pythonfilename.string()+":\"\n"); 64 63 enveloped_script += pythonscript; 65 enveloped_script += std::string("print \"END of "+pythonfilename _string+":\"\n");64 enveloped_script += std::string("print \"END of "+pythonfilename.string()+":\"\n"); 66 65 67 66 boost::python::handle<> ignored(( PyRun_String( enveloped_script.c_str(), … … 78 77 return false; 79 78 } 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.