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
24 from .docwriter import DocWriter
25 from .sectionparser import generate_sections_file, write_sections_file
26 from .transformer import Transformer
30 parser = optparse.OptionParser('%prog [options] GIR-file')
32 parser.add_option("-o", "--output",
33 action="store", dest="output",
34 help="Directory to write output to")
35 parser.add_option("-l", "--language",
36 action="store", dest="language",
38 help="Output language")
39 parser.add_option("", "--add-include-path",
40 action="append", dest="include_paths", default=[],
41 help="include paths for other GIR files")
42 parser.add_option("", "--write-sections-file",
43 action="store_true", dest="write_sections",
44 help="Generate and write out a sections file")
46 options, args = parser.parse_args(args)
47 if not options.output:
48 raise SystemExit("missing output parameter")
51 raise SystemExit("Need an input GIR filename")
53 if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
54 top_srcdir = os.environ['UNINSTALLED_INTROSPECTION_SRCDIR']
55 top_builddir = os.environ['UNINSTALLED_INTROSPECTION_BUILDDIR']
56 extra_include_dirs = [os.path.join(top_srcdir, 'gir'), top_builddir]
58 extra_include_dirs = []
59 extra_include_dirs.extend(options.include_paths)
60 transformer = Transformer.parse_from_gir(args[1], extra_include_dirs)
62 if options.write_sections:
63 sections_file = generate_sections_file(transformer)
65 fp = open(options.output, 'w')
66 write_sections_file(fp, sections_file)
69 writer = DocWriter(transformer, options.language)
70 writer.write(options.output)