]> Dogcows Code - chaz/openbox/commitdiff
execute files such that i can track if an exception was thrown in it
authorDana Jansens <danakj@orodu.net>
Sun, 16 Feb 2003 16:33:37 +0000 (16:33 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Feb 2003 16:33:37 +0000 (16:33 +0000)
src/python.cc

index 08f8f506139cf2398f8ce25c511500789c0cb82f..eb08775e08d7a5356288ee8e56f521a3c9cdda46 100644 (file)
@@ -10,6 +10,9 @@
 
 extern "C" {
 #include <Python.h>
+
+#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<char*>(path.c_str()));
+
+  //PyRun_SimpleFile(rcpyfd, const_cast<char*>(path.c_str()));
+
+  PyObject *module = PyImport_AddModule("__main__");
+  assert(module);
+  PyObject *dict = PyModule_GetDict(module);
+  assert(dict);
+  PyObject *result = PyRun_File(rcpyfd, const_cast<char*>(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;
 }
 
 }
This page took 0.028589 seconds and 4 git commands to generate.