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
23 from .docbookwriter import DocBookWriter
24 from .docbookwriter import DocBookFormatterC
25 from .docbookwriter import DocBookFormatterPython
26 from .transformer import Transformer
28 class GIDocGenerator(object):
30 def parse(self, filename):
31 self.transformer = Transformer.parse_from_gir(filename)
33 def generate(self, writer, output):
34 writer.add_transformer(self.transformer)
38 parser = optparse.OptionParser('%prog [options] GIR-file')
40 parser.add_option("-o", "--output",
41 action="store", dest="output",
42 help="Filename to write output")
43 parser.add_option("-f", "--format",
44 action="store", dest="format",
47 parser.add_option("-l", "--language",
48 action="store", dest="language",
50 help="Output language")
52 options, args = parser.parse_args(args)
53 if not options.output:
54 raise SystemExit("missing output parameter")
57 raise SystemExit("Need an input GIR filename")
59 if options.language == "Python":
60 formatter = DocBookFormatterPython()
61 elif options.language == "C":
62 formatter = DocBookFormatterC()
64 raise SystemExit("Unsupported language: %s" % (options.language, ))
66 if options.format == "docbook":
67 writer = DocBookWriter(formatter)
69 raise SystemExit("Unsupported output format: %s" % (options.format, ))
71 generator = GIDocGenerator()
72 generator.parse(args[1])
74 generator.generate(writer, options.output)