From 27e7665c4805eab2f4d97b99436e471cf7ba945c Mon Sep 17 00:00:00 2001 From: John Ehresman Date: Thu, 15 Apr 2010 12:57:22 -0400 Subject: Python 3 support for setup.py --- codegen/docextract_to_xml.py | 101 ++++++++++--------------------------------- 1 file changed, 22 insertions(+), 79 deletions(-) (limited to 'codegen/docextract_to_xml.py') diff --git a/codegen/docextract_to_xml.py b/codegen/docextract_to_xml.py index 775b57d..f8d3bae 100755 --- a/codegen/docextract_to_xml.py +++ b/codegen/docextract_to_xml.py @@ -13,18 +13,6 @@ import sys import docextract -def usage(): - sys.stderr.write('usage: docextract_to_xml.py ' + - '[-s /src/dir | --source-dir=/src/dir] ' + - '[-a | --with-annotations] [-p | --with-properties] ' + - '[-i | --with-signals ]\n') - sys.exit(1) - -# Translates special texts to &... HTML acceptable format. Also replace -# occurrences of '/*' and '*/' with '/ *' and '* /' respectively to avoid -# comment errors (note the spaces). Some function descriptions include C++ -# multi-line comments which cause errors when the description is included in a -# C++ Doxygen comment block. def escape_text(unescaped_text): # Escape every "&" not part of an entity reference escaped_text = re.sub(r'&(?![A-Za-z]+;)', '&', unescaped_text) @@ -34,51 +22,31 @@ def escape_text(unescaped_text): escaped_text = string.replace(escaped_text, '*', '*') escaped_text = string.replace(escaped_text, '%', '%') escaped_text = string.replace(escaped_text, '@', '@') - escaped_text = string.replace(escaped_text, '#', '') - escaped_text = string.replace(escaped_text, ' ', ' ') - # This represents a '/' before or after an '*' so replace with slash but - # with spaces. - escaped_text = string.replace(escaped_text, '/', ' / ') # Escape for both tag contents and attribute values escaped_text = string.replace(escaped_text, '<', '<') escaped_text = string.replace(escaped_text, '>', '>') escaped_text = string.replace(escaped_text, '"', '"') - # Replace C++ comment begin and ends to ones that don't affect Doxygen. - escaped_text = string.replace(escaped_text, '/*', '/ *') - escaped_text = string.replace(escaped_text, '*/', '* /') - return escaped_text -def print_annotations(annotations): - for annotation in annotations: - print "" + \ - escape_text(annotation[1]) + "" - if __name__ == '__main__': try: - opts, args = getopt.getopt(sys.argv[1:], "d:s:o:api", - ["source-dir=", "with-annotations", - "with-properties", "with-signals"]) + opts, args = getopt.getopt(sys.argv[1:], "d:s:o:", + ["source-dir="]) except getopt.error, e: - sys.stderr.write('docextract_to_xml.py: %s\n' % e) - usage() + sys.stderr.write('docgen.py: %s\n' % e) + sys.stderr.write( + 'usage: docgen.py [-s /src/dir]\n') + sys.exit(1) source_dirs = [] - with_annotations = False - with_signals = False - with_properties = False for opt, arg in opts: if opt in ('-s', '--source-dir'): source_dirs.append(arg) - if opt in ('-a', '--with-annotations'): - with_annotations = True - if opt in ('-p', '--with-properties'): - with_properties = True - if opt in ('-i', '--with-signals'): - with_signals = True if len(args) != 0: - usage() + sys.stderr.write( + 'usage: docgen.py [-s /src/dir]\n') + sys.exit(1) docs = docextract.extract(source_dirs); docextract.extract_tmpl(source_dirs, docs); #Try the tmpl sgml files too. @@ -90,50 +58,25 @@ if __name__ == '__main__': print "" for name, value in docs.items(): - # Get the type of comment block ('function', 'signal' or - # 'property') (the value is a GtkDoc). - block_type = value.get_type() - - # Skip signals if the option was not specified. - if block_type == 'signal' and not with_signals: - continue - # Likewise for properties. - elif block_type == 'property' and not with_properties: - continue - - print "<" + block_type + " name=\"" + escape_text(name) + "\">" + print "" print "" - print escape_text(value.get_description()) + #The value is a docextract.FunctionDoc + print escape_text(value.description) print "" - # Loop through the parameters if not dealing with a property: - if block_type != 'property': - print "" - for name, description, annotations in value.params: - print "" - print "" + escape_text(description) + "" - - if with_annotations: - print_annotations(annotations) - - print "" - - print "" + # Loop through the parameters: + print "" + for name, description in value.params: + print "" + print "" + escape_text(description) + "" + print "" - # Show the return-type (also if not dealing with a property): - if with_annotations: - print "" - print "" + escape_text(value.ret[0]) + \ - "" - print_annotations(value.ret[1]) - print "" - else: - print "" + escape_text(value.ret[0]) + "" + print "" - if with_annotations: - print_annotations(value.get_annotations()) + # Show the return-type: + print "" + escape_text(value.ret) + "" - print "\n" + print "\n" print "" -- cgit