[docbook] Make DocBookWriter use Transformer
[platform/upstream/gobject-introspection.git] / giscanner / docmain.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008-2011 Johan Dahlin
4 #
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.
9 #
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.
14 #
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
18 # 02110-1301, USA.
19 #
20
21 import optparse
22
23 from .docbookwriter import DocBookWriter
24 from .transformer import Transformer
25
26 class GIDocGenerator(object):
27
28     def parse(self, filename):
29         self.transformer = Transformer.parse_from_gir(filename)
30
31     def generate(self, writer, output):
32         writer.add_transformer(self.transformer)
33         writer.write(output)
34
35 def doc_main(args):
36     parser = optparse.OptionParser('%prog [options] GIR-file')
37
38     parser.add_option("-o", "--output",
39                       action="store", dest="output",
40                       help="Filename to write output")
41     parser.add_option("-f", "--format",
42                       action="store", dest="format",
43                       default="docbook",
44                       help="Output format")
45
46     options, args = parser.parse_args(args)
47     if not options.output:
48         raise SystemExit("missing output parameter")
49
50     if len(args) < 2:
51         raise SystemExit("Need an input GIR filename")
52
53     if options.format == "docbook":
54         writer = DocBookWriter()
55     else:
56         raise SystemExit("Unsupported output format: %s" % (options.format, ))
57
58     generator = GIDocGenerator()
59     generator.parse(args[1])
60
61     generator.generate(writer, options.output)
62
63     return 0