Add gobject-introspection.changes file
[profile/ivi/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 os
22 import optparse
23
24 from .mallardwriter import MallardWriter
25 from .transformer import Transformer
26
27 def doc_main(args):
28     parser = optparse.OptionParser('%prog [options] GIR-file')
29
30     parser.add_option("-o", "--output",
31                       action="store", dest="output",
32                       help="Directory to write output to")
33     parser.add_option("-l", "--language",
34                       action="store", dest="language",
35                       default="Python",
36                       help="Output language")
37
38     options, args = parser.parse_args(args)
39     if not options.output:
40         raise SystemExit("missing output parameter")
41     if not os.path.isdir(options.output):
42         raise SystemExit("wrong output parameter: %s", options.output)
43
44     if len(args) < 2:
45         raise SystemExit("Need an input GIR filename")
46
47     if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
48         top_srcdir = os.environ['UNINSTALLED_INTROSPECTION_SRCDIR']
49         top_builddir = os.environ['UNINSTALLED_INTROSPECTION_BUILDDIR']
50         extra_include_dirs = [os.path.join(top_srcdir, 'gir'), top_builddir]
51     else:
52         extra_include_dirs = []
53     transformer = Transformer.parse_from_gir(args[1], extra_include_dirs)
54
55     writer = MallardWriter(transformer, options.language)
56     writer.write(options.output)
57
58     return 0