Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Python/PythonScripting.cpp

    r2cf12a r57388c9  
    3939#include "CodePatterns/MemDebug.hpp"
    4040
    41 bool executePythonScriptFile(const boost::filesystem::path &pythonfilename)
     41bool executePythonScript(const std::string &pythonfilename_string)
    4242{
     43  boost::filesystem::path pythonfilename(pythonfilename_string);
    4344  if (exists(pythonfilename)) {
    4445    // parse in and execute the local and global config.py
     
    6061      std::string pythonscript( std::istreambuf_iterator<char>(pythonfile),
    6162          (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");
    6364      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");
    6566
    6667      boost::python::handle<> ignored(( PyRun_String( enveloped_script.c_str(),
     
    7778  return false;
    7879}
    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.