plugin: Don't import modules that were already imported.

This avoids warnings for the cases where pygst.require() was already
called.
This commit is contained in:
Edward Hervey 2009-02-27 12:29:04 +01:00
parent 3f5c8795c3
commit 6d6781e01f

View file

@ -252,22 +252,32 @@ pygst_require (gchar * version)
{
PyObject *pygst, *gst;
PyObject *require;
PyObject *modules;
if (!(pygst = PyImport_ImportModule ("pygst"))) {
GST_ERROR ("the pygst module is not available!");
goto error;
}
modules = PySys_GetObject ("modules");
/* Try to see if 'gst' is already imported */
if (!(gst = PyMapping_GetItemString (modules, "gst"))) {
if (!(PyObject_CallMethod (pygst, "require", "s", version))) {
GST_ERROR ("the required version, %s, of gst-python is not available!");
Py_DECREF (pygst);
goto error;
}
/* if not, see if 'pygst' was already imported. If so, we assume that
* 'pygst.require' has already been called. */
if (!(pygst = PyMapping_GetItemString (modules, "pygst"))) {
if (!(pygst = PyImport_ImportModule ("pygst"))) {
GST_ERROR ("the pygst module is not available!");
goto error;
}
if (!(gst = PyImport_ImportModule ("gst"))) {
GST_ERROR ("couldn't import the gst module");
Py_DECREF (pygst);
goto error;
if (!(PyObject_CallMethod (pygst, "require", "s", version))) {
GST_ERROR ("the required version, %s, of gst-python is not available!",
version);
Py_DECREF (pygst);
goto error;
}
}
if (!(gst = PyImport_ImportModule ("gst"))) {
GST_ERROR ("couldn't import the gst module");
Py_DECREF (pygst);
goto error;
}
}
#define IMPORT(x, y) \
_PyGst##x##_Type = (PyTypeObject *)PyObject_GetAttrString(gst, y); \