summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu.duponchelle@opencreed.com>2015-03-10 15:49:47 +0100
committerJasper St. Pierre <jstpierre@mecheye.net>2015-06-17 14:23:52 -0700
commit86e17e6853187d5e6983c39980b6df9e4b82edbd (patch)
tree6e2253166147512135397b79d179f3fb4bb48f7c
parentecc8974a453e14cca3a061c174daa10044e02e85 (diff)
downloadgobject-introspection-86e17e6853187d5e6983c39980b6df9e4b82edbd.tar.gz
docmain: port to using argparse.
optparse is deprecated.
-rw-r--r--configure.ac2
-rw-r--r--giscanner/docmain.py32
2 files changed, 16 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac
index 115e49b3..ebf02067 100644
--- a/configure.ac
+++ b/configure.ac
@@ -251,7 +251,7 @@ AC_CHECK_FUNCS([memchr strchr strspn strstr strtol strtoull])
AC_CHECK_FUNCS([backtrace backtrace_symbols])
# Python
-AM_PATH_PYTHON([2.6])
+AM_PATH_PYTHON([2.7])
case "$host" in
*-*-mingw*)
# Change backslashes to forward slashes in pyexecdir to avoid
diff --git a/giscanner/docmain.py b/giscanner/docmain.py
index e65b57a0..fdcda18f 100644
--- a/giscanner/docmain.py
+++ b/giscanner/docmain.py
@@ -19,7 +19,7 @@
#
import os
-import optparse
+import argparse
from .docwriter import DocWriter
from .sectionparser import generate_sections_file, write_sections_file
@@ -27,46 +27,44 @@ from .transformer import Transformer
def doc_main(args):
- parser = optparse.OptionParser('%prog [options] GIR-file')
+ parser = argparse.ArgumentParser()
- parser.add_option("-o", "--output",
+ parser.add_argument("girfile")
+ parser.add_argument("-o", "--output",
action="store", dest="output",
help="Directory to write output to")
- parser.add_option("-l", "--language",
+ parser.add_argument("-l", "--language",
action="store", dest="language",
default="c",
help="Output language")
- parser.add_option("", "--add-include-path",
+ parser.add_argument("-I", "--add-include-path",
action="append", dest="include_paths", default=[],
help="include paths for other GIR files")
- parser.add_option("", "--write-sections-file",
+ parser.add_argument("-s", "--write-sections-file",
action="store_true", dest="write_sections",
help="Generate and write out a sections file")
- options, args = parser.parse_args(args)
- if not options.output:
+ args = parser.parse_args(args[1:])
+ if not args.output:
raise SystemExit("missing output parameter")
- if len(args) < 2:
- raise SystemExit("Need an input GIR filename")
-
if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
top_srcdir = os.environ['UNINSTALLED_INTROSPECTION_SRCDIR']
top_builddir = os.environ['UNINSTALLED_INTROSPECTION_BUILDDIR']
extra_include_dirs = [os.path.join(top_srcdir, 'gir'), top_builddir]
else:
extra_include_dirs = []
- extra_include_dirs.extend(options.include_paths)
- transformer = Transformer.parse_from_gir(args[1], extra_include_dirs)
+ extra_include_dirs.extend(args.include_paths)
+ transformer = Transformer.parse_from_gir(args.girfile, extra_include_dirs)
- if options.write_sections:
+ if args.write_sections:
sections_file = generate_sections_file(transformer)
- fp = open(options.output, 'w')
+ fp = open(args.output, 'w')
write_sections_file(fp, sections_file)
fp.close()
else:
- writer = DocWriter(transformer, options.language)
- writer.write(options.output)
+ writer = DocWriter(transformer, args.language)
+ writer.write(args.output)
return 0