X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fpython.cc;fp=src%2Fpython.cc;h=eb08775e08d7a5356288ee8e56f521a3c9cdda46;hb=c8789ccdbf40c8f0730cbe4c68b8f43b2d9a7f85;hp=08f8f506139cf2398f8ce25c511500789c0cb82f;hpb=8ed79248e79cede45b6972f3ab007add1dd55956;p=chaz%2Fopenbox diff --git a/src/python.cc b/src/python.cc index 08f8f506..eb08775e 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 { @@ -36,12 +39,28 @@ bool 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()); + fprintf(stderr, _("Unabled to open python file %s\n"), path.c_str()); return false; } - 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); + bool ret = result != NULL; + if (result == NULL) + PyErr_Print(); + + Py_XDECREF(result); + + Py_DECREF(dict); + fclose(rcpyfd); - return true; + return ret; } }