After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 469763 - Use OptionParser to parse options
Use OptionParser to parse options
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: codegen
2.15.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2007-08-24 00:16 UTC by Björn Lindqvist
Modified: 2012-02-10 08:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Replace getopt with OptionParser, provide nice help page (5.39 KB, patch)
2007-08-24 00:20 UTC, Björn Lindqvist
none Details | Review

Description Björn Lindqvist 2007-08-24 00:16:46 UTC
In the patch below, I have replaced codegen.py's getopt based option parsing with OptionParser. There are no feature changes but some nicities added:

before:

$ python codegen.py
usage: codegen.py [-o overridesfile] [-p prefix] defsfile

after:

$ python codegen.py
usage: codegen.py [options] defsfile

options:
  -o OVERRIDE, --override=OVERRIDE
                        overrides file
  -p PREFIX, --prefix=PREFIX
                        prefix for variable names inside generated code
  -r REGISTER, --register=REGISTER
                        file with types to register
  --outfilename=OUTFILENAME
                        c file to generate
  --errorfilename=ERRORFILENAME
                        file to log errors to
  --py_ssize_t_clean    set py_ssize_t_clean
  -D DEFINES            add preprocessor definition key-value
  -I INCLUDES           add include path
  -t LOAD_TYPES, --load-types=LOAD_TYPES
                        script to load before code generation
  -h, --help            show this help message and exit

The option descriptions might not be 100% correct, I had to make educated guesses at what the undocumented options do. There is also some more exception handling so you should (in more cases) get an error message instead of a traceback when a file is missing. 

I cannot swear that the patch doesn't break something, but I've tried running it on some examples and it seems to work ok. So someone else should try it too. It incidentally solves the silent error "python codegen.py -r foobar.defs -DMOO=BOO" since OptionParser-parsing is position independent.
Comment 1 Björn Lindqvist 2007-08-24 00:20:51 UTC
Created attachment 94228 [details] [review]
Replace getopt with OptionParser, provide nice help page
Comment 2 Martin Pitt 2012-02-10 08:08:08 UTC
codegen is obsolete with pygobject 3.0, which is GI only.