summaryrefslogtreecommitdiff
path: root/c/python.c
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-03-16 21:11:39 +0000
committerDana Jansens <danakj@orodu.net>2003-03-16 21:11:39 +0000
commitf8a47de5ec444c452093371e3db16857eb39a490 (patch)
tree31db2567842d98232775f9980f7a8d2586c0ac71 /c/python.c
parent8ba0586bcbdc7fe9648f1063812126d71a041670 (diff)
merge the C branch into HEAD
Diffstat (limited to 'c/python.c')
-rw-r--r--c/python.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/c/python.c b/c/python.c
new file mode 100644
index 00000000..6622ed8a
--- /dev/null
+++ b/c/python.c
@@ -0,0 +1,55 @@
+#include <Python.h>
+#include <glib.h>
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+void python_startup()
+{
+ PyObject *sys, *sysdict, *syspath, *path1, *path2;
+ char *home, *homescriptdir;
+
+ Py_Initialize();
+
+ /* fix up the system path */
+
+ sys = PyImport_ImportModule((char*)"sys"); /* new */
+ sysdict = PyModule_GetDict(sys); /* borrowed */
+ syspath = PyDict_GetItemString(sysdict, (char*)"path"); /* borrowed */
+
+ path1 = PyString_FromString(SCRIPTDIR); /* new */
+ PyList_Insert(syspath, 0, path1);
+ Py_DECREF(path1);
+
+ home = getenv("HOME");
+ if (home != NULL) {
+ homescriptdir = g_strdup_printf("%s/.openbox", home);
+ path2 = PyString_FromString(homescriptdir); /* new */
+ g_free(homescriptdir);
+
+ PyList_Insert(syspath, 0, path2);
+ Py_DECREF(path2);
+ } else
+ g_warning("Failed to read the $HOME environment variable");
+
+ Py_DECREF(sys);
+}
+
+void python_shutdown()
+{
+ Py_Finalize();
+}
+
+gboolean python_import(char *module)
+{
+ PyObject *mod;
+
+ mod = PyImport_ImportModule(module); /* new */
+ if (mod == NULL) {
+ PyErr_Print();
+ return FALSE;
+ }
+ Py_DECREF(mod);
+ return TRUE;
+}