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 .docbookwriter import DocBookWriter
25 from .docbookwriter import DocBookFormatterC
26 from .docbookwriter import DocBookFormatterPython
27 from .mallardwriter import MallardWriter
28 from .mallardwriter import MallardFormatterC
29 from .mallardwriter import MallardFormatterPython
30 from .transformer import Transformer
32 class GIDocGenerator(object):
34 def parse(self, filename):
35 if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
36 top_srcdir = os.environ['UNINSTALLED_INTROSPECTION_SRCDIR']
37 top_builddir = os.environ['UNINSTALLED_INTROSPECTION_BUILDDIR']
38 extra_include_dirs = [os.path.join(top_srcdir, 'gir'), top_builddir]
40 extra_include_dirs = []
41 self.transformer = Transformer.parse_from_gir(filename, extra_include_dirs)
43 def generate(self, writer, output):
44 writer.add_transformer(self.transformer)
48 parser = optparse.OptionParser('%prog [options] GIR-file')
50 parser.add_option("-o", "--output",
51 action="store", dest="output",
52 help="Filename to write output")
53 parser.add_option("-f", "--format",
54 action="store", dest="format",
57 parser.add_option("-l", "--language",
58 action="store", dest="language",
60 help="Output language")
62 options, args = parser.parse_args(args)
63 if not options.output:
64 raise SystemExit("missing output parameter")
67 raise SystemExit("Need an input GIR filename")
69 if options.format == "docbook":
70 if options.language == "Python":
71 formatter = DocBookFormatterPython()
72 elif options.language == "C":
73 formatter = DocBookFormatterC()
75 raise SystemExit("Unsupported language: %s" % (options.language, ))
76 writer = DocBookWriter(formatter)
77 elif options.format == "mallard":
78 if options.language == "Python":
79 formatter = MallardFormatterPython()
80 elif options.language == "C":
81 formatter = MallardFormatterC()
83 raise SystemExit("Unsupported language: %s" % (options.language, ))
84 writer = MallardWriter(formatter)
86 raise SystemExit("Unsupported output format: %s" % (options.format, ))
88 generator = GIDocGenerator()
89 generator.parse(args[1])
91 generator.generate(writer, options.output)