[gobject-introspection] docmain: port to using argparse.
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] docmain: port to using argparse.
- Date: Wed, 17 Jun 2015 21:24:18 +0000 (UTC)
commit 86e17e6853187d5e6983c39980b6df9e4b82edbd
Author: Mathieu Duponchelle <mathieu duponchelle opencreed com>
Date: Tue Mar 10 15:49:47 2015 +0100
docmain: port to using argparse.
optparse is deprecated.
configure.ac | 2 +-
giscanner/docmain.py | 32 +++++++++++++++-----------------
2 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 115e49b..ebf0206 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 e65b57a..fdcda18 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]