Imported Upstream version 1.37.1
[platform/upstream/gobject-introspection.git] / giscanner / annotationmain.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2010 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 giscanner import message
24 from giscanner.annotationparser import AnnotationParser
25 from giscanner.scannermain import (get_preprocessor_option_group,
26                                    create_source_scanner,
27                                    process_packages)
28
29
30 def annotation_main(args):
31     parser = optparse.OptionParser('%prog [options] sources')
32
33     group = optparse.OptionGroup(parser, "Tool modes, one is required")
34     group.add_option("-e", "--extract",
35                      action="store_true", dest="extract",
36                      help="Extract annotations from the input files")
37     parser.add_option_group(group)
38
39     group = get_preprocessor_option_group(parser)
40     group.add_option("-L", "--library-path",
41                      action="append", dest="library_paths", default=[],
42                      help="directories to search for libraries")
43     group.add_option("", "--pkg",
44                      action="append", dest="packages", default=[],
45                      help="pkg-config packages to get cflags from")
46     parser.add_option_group(group)
47
48     options, args = parser.parse_args(args)
49
50     if not options.extract:
51         raise SystemExit("ERROR: Nothing to do")
52
53     if options.packages:
54         process_packages(options, options.packages)
55
56     logger = message.MessageLogger.get(namespace=None)
57
58     ss = create_source_scanner(options, args)
59
60     if options.extract:
61         ap = AnnotationParser()
62         blocks = ap.parse(ss.get_comments())
63         print '/' + ('*' * 60) + '/'
64         print '/* THIS FILE IS GENERATED DO NOT EDIT */'
65         print '/' + ('*' * 60) + '/'
66         print
67         for block in sorted(blocks.values()):
68             print block.to_gtk_doc()
69             print
70         print
71         print '/' + ('*' * 60) + '/'
72         print '/* THIS FILE IS GENERATED DO NOT EDIT */'
73         print '/' + ('*' * 60) + '/'
74
75     return 0