X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fpython.cc;h=0741f2da940e4df8f40e4cb8ef91ab9e8ab84844;hb=fbfa2798623ffa2ae34946070d35eb529a6cb6a9;hp=08f8f506139cf2398f8ce25c511500789c0cb82f;hpb=059bc4dc24b68d637c3608c05344c53c64cc2c4b;p=chaz%2Fopenbox diff --git a/src/python.cc b/src/python.cc index 08f8f506..0741f2da 100644 --- a/src/python.cc +++ b/src/python.cc @@ -10,6 +10,9 @@ extern "C" { #include + +#include "gettext.h" +#define _(str) gettext(str) } namespace ob { @@ -32,16 +35,32 @@ void python_destroy() Py_Finalize(); } -bool python_exec(const std::string &path) +int python_exec(const std::string &path) { FILE *rcpyfd = fopen(path.c_str(), "r"); if (!rcpyfd) { - printf("Failed to load python file %s\n", path.c_str()); - return false; + fprintf(stderr, _("Unabled to open python file %s\n"), path.c_str()); + return 1; } - PyRun_SimpleFile(rcpyfd, const_cast(path.c_str())); + + //PyRun_SimpleFile(rcpyfd, const_cast(path.c_str())); + + PyObject *module = PyImport_AddModule("__main__"); + assert(module); + PyObject *dict = PyModule_GetDict(module); + assert(dict); + PyObject *result = PyRun_File(rcpyfd, const_cast(path.c_str()), + Py_file_input, dict, dict); + int ret = result == NULL ? 2 : 0; + if (result == NULL) + PyErr_Print(); + + Py_XDECREF(result); + + Py_DECREF(dict); + fclose(rcpyfd); - return true; + return ret; } }