GNOME Bugzilla – Bug 425847
Silently overrides some functions of default module optparse
Last modified: 2012-05-20 18:16:52 UTC
Please describe the problem: gst-python seems to influence the behaviour of optparse.OptionParser() when invoke with --help. Doing and `import gst` in a python program using optparse will cause all help text to be displayed like this: Usage: istanbul [OPTION...] - GStreamer initialization Help Options: -?, --help Show help options --help-all Show all help options --help-gst Show GStreamer Options Application Options: If you import gst after parsing the arguments, all works fine, displaying original help text. This bug is being worked around in many applications (like istanbul and jokosher) just postponing `import gst`, but it would be better fixed directly in gst-python Steps to reproduce: 1. import gst, optparse 2. implement optparse.OptionParser() 3. launch your app with --help 4. try again without importing gst to see the difference Actual results: steps 1,2,3: a fixed help text which says: Usage: istanbul [OPTION...] - GStreamer initialization Help Options: -?, --help Show help options --help-all Show all help options --help-gst Show GStreamer Options Application Options: Expected results: the same as step 4: see my custom help text :). Does this happen every time? Yes Other information:
The problem is unrelated to optparse though. Consider this simple example session: >>> import sys >>> sys.argv.append ("--help") >>> import pygst; pygst.require ("0.10"); import gst Usage: . [OPTION...] - GStreamer initialization Help Options: -?, --help Show help options --help-all Show all help options --help-gst Show GStreamer Options Application Options: The problem is that the gst module does not act like library. Instead, it performs the I'm-a-simple/stupid-program procedure by calling gst_init_check.
I can confirm this. The problem is that when you do "import gst" in your program the python bindings will parse the command line arguments using GOption internally so you will not have a chance to hook in your own arguments with the ones provided by GStreamer.
Created attachment 98377 [details] [review] patch Here is a way to solve this. The patch includes an example. This depends on bug 492701.
Created attachment 98578 [details] [review] v2: with pygobject version check
2007-11-05 Johan Dahlin <johan@gnome.org> * gstoptionmodule.c: * Makefile.am: * configure.ac: Add a new module, gstoption which allows you to fetch the GOptionGroup from gstreamer without initializing and parsing the command line arguments. Requires PyGObject 2.15.0 Fixes #425847 * examples/option-parser.py (main): Example
Would it be possible to remove the automatic parsing behaviour from gstreamer, so our programs can import gst at the top of the file, instead of delaying it? It would really be nice to not have to work around this, and be able to do gst.get_group(), but maybe this is a backwards compatibility issue. Btw, is there any documentation/example for getting the option group from gtk?
This bug is still not fixed. Can we make pygst to not parse options (best) or at least not have to hack around by putting import gst after parsing?
I can confirm that this is not fixed. The gstreamer module should only parse options if specifically asked to do so.