2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008-2011 Johan Dahlin
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 from .docwriter import DocWriter
26 from .sectionparser import generate_sections_file, write_sections_file
27 from .transformer import Transformer
29 FORMATS = ('devdocs', 'mallard', 'sections')
33 parser = argparse.ArgumentParser()
34 parser.add_argument('--version', action='version',
35 version='%(prog)s ' + giscanner.__version__)
36 parser.add_argument("girfile")
37 parser.add_argument("-o", "--output",
38 action="store", dest="output",
39 help="Directory to write output to")
40 parser.add_argument("-l", "--language",
41 action="store", dest="language",
43 help="Output language")
44 parser.add_argument("-f", "--format",
45 action="store", dest="format",
46 choices=FORMATS, default=FORMATS[1],
48 parser.add_argument("-I", "--add-include-path",
49 action="append", dest="include_paths", default=[],
50 help="include paths for other GIR files")
51 parser.add_argument("-s", "--write-sections-file",
52 action="store_const", dest="format", const="sections",
53 help="Backwards-compatible equivalent to -f sections")
55 args = parser.parse_args(args[1:])
57 raise SystemExit("missing output parameter")
58 if args.format not in FORMATS:
59 raise SystemExit("Unknown output format %s (supported: %s)" %
60 (args.format, ", ".join(FORMATS)))
62 if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
63 top_srcdir = os.environ['UNINSTALLED_INTROSPECTION_SRCDIR']
64 top_builddir = os.environ['UNINSTALLED_INTROSPECTION_BUILDDIR']
65 extra_include_dirs = [os.path.join(top_srcdir, 'gir'), top_builddir]
67 extra_include_dirs = []
68 extra_include_dirs.extend(args.include_paths)
69 transformer = Transformer.parse_from_gir(args.girfile, extra_include_dirs)
71 if args.format == 'sections':
72 sections_file = generate_sections_file(transformer)
74 with open(args.output, 'w', encoding='utf-8') as fp:
75 write_sections_file(fp, sections_file)
77 writer = DocWriter(transformer, args.language, args.format)
78 writer.write(args.output)