123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- from __future__ import absolute_import
- from __future__ import division
- from __future__ import print_function
- from __future__ import unicode_literals
- import sys
- import optparse
- import codecs
- from contextlib import contextmanager
- from giscanner import message
- from giscanner.annotationparser import GtkDocCommentBlockParser, GtkDocCommentBlockWriter
- from giscanner.scannermain import (get_preprocessor_option_group,
- create_source_scanner,
- process_packages)
- @contextmanager
- def encode_stdout(encoding):
- """Force stdout into a specific encoding."""
-
-
-
-
- old_stdout = sys.stdout
- if sys.version_info.major < 3:
- binary_stdout = sys.stdout
- else:
- binary_stdout = sys.stdout.buffer
- sys.stdout = codecs.getwriter(encoding)(binary_stdout)
- yield
- sys.stdout = old_stdout
- def annotation_main(args):
- parser = optparse.OptionParser('%prog [options] sources')
- group = optparse.OptionGroup(parser, "Tool modes, one is required")
- group.add_option("-e", "--extract",
- action="store_true", dest="extract",
- help="Extract annotations from the input files")
- parser.add_option_group(group)
- group = get_preprocessor_option_group(parser)
- group.add_option("-L", "--library-path",
- action="append", dest="library_paths", default=[],
- help="directories to search for libraries")
- group.add_option("", "--pkg",
- action="append", dest="packages", default=[],
- help="pkg-config packages to get cflags from")
- parser.add_option_group(group)
- options, args = parser.parse_args(args)
- if not options.extract:
- raise SystemExit("ERROR: Nothing to do")
- if options.packages:
- process_packages(options, options.packages)
- logger = message.MessageLogger.get(namespace=None)
- ss = create_source_scanner(options, args)
- if options.extract:
- parser = GtkDocCommentBlockParser()
- writer = GtkDocCommentBlockWriter(indent=False)
- blocks = parser.parse_comment_blocks(ss.get_comments())
- with encode_stdout('utf-8'):
- print('/' + ('*' * 60) + '/')
- print('/* THIS FILE IS GENERATED DO NOT EDIT */')
- print('/' + ('*' * 60) + '/')
- print('')
- for block in sorted(blocks.values()):
- print(writer.write(block))
- print('')
- print('')
- print('/' + ('*' * 60) + '/')
- print('/* THIS FILE IS GENERATED DO NOT EDIT */')
- print('/' + ('*' * 60) + '/')
- return 0
|