[pygobject/gsoc2009: 41/160] Add wrapper for g_irepository_get_typelib_path



commit f8935d5dbf2d06248b9d3adbf4b0b57d2c0810d1
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Wed Jul 15 12:16:36 2009 +0200

    Add wrapper for g_irepository_get_typelib_path
    
    And show the path in DynamicModule.__str__.

 gi/module.py        |    3 ++-
 gi/pygirepository.c |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 4e4d8d0..6bac1f1 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -66,7 +66,8 @@ def get_parent_for_object(object_info):
 class DynamicModule(object):
 
     def __str__(self):
-        return "<dynamic module %r>" % self.__name__
+        path = repository.get_typelib_path(self.__namespace__)
+        return "<dynamic module %r from %r>" % (self.__name__,  path)
 
     def __getattr__(self, name):
         info = repository.find_by_name(self.__namespace__, name)
diff --git a/gi/pygirepository.c b/gi/pygirepository.c
index fa8065d..879f7d0 100644
--- a/gi/pygirepository.c
+++ b/gi/pygirepository.c
@@ -199,6 +199,29 @@ _wrap_g_irepository_get_c_prefix(PyGIRepository *self,
 }
 
 static PyObject *
+_wrap_g_irepository_get_typelib_path(PyGIRepository *self,
+                                     PyObject *args,
+                                     PyObject *kwargs)
+{
+    static char *kwlist[] = { "namespace", NULL };
+    gchar *namespace_;
+    const gchar *typelib_path;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+            "s:Repository.get_typelib_path", kwlist, &namespace_)) {
+        return NULL;
+    }
+
+    typelib_path = g_irepository_get_typelib_path(self->repository, namespace_);
+    if (typelib_path == NULL) {
+        PyErr_Format(PyExc_RuntimeError, "Namespace '%s' not loaded", namespace_);
+        return NULL;
+    }
+
+    return PyString_FromString(typelib_path);
+}
+
+static PyObject *
 _wrap_g_irepository_get_default(PyObject *self)
 {
     static PyGIRepository *repository = NULL;
@@ -224,6 +247,7 @@ static PyMethodDef _PyGIRepository_methods[] = {
     { "find_by_name", (PyCFunction)_wrap_g_irepository_find_by_name, METH_VARARGS|METH_KEYWORDS },
     { "is_registered", (PyCFunction)_wrap_g_irepository_is_registered, METH_VARARGS|METH_KEYWORDS },
     { "get_c_prefix", (PyCFunction)_wrap_g_irepository_get_c_prefix, METH_VARARGS|METH_KEYWORDS },
+    { "get_typelib_path", (PyCFunction)_wrap_g_irepository_get_typelib_path, METH_VARARGS|METH_KEYWORDS },
     { NULL, NULL, 0 }
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]