diff options
Diffstat (limited to 'codegen/docextract_to_xml.py')
-rwxr-xr-x | codegen/docextract_to_xml.py | 87 |
1 files changed, 65 insertions, 22 deletions
diff --git a/codegen/docextract_to_xml.py b/codegen/docextract_to_xml.py index f8d3bae..638ac94 100755 --- a/codegen/docextract_to_xml.py +++ b/codegen/docextract_to_xml.py @@ -13,6 +13,13 @@ 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) + def escape_text(unescaped_text): # Escape every "&" not part of an entity reference escaped_text = re.sub(r'&(?![A-Za-z]+;)', '&', unescaped_text) @@ -30,23 +37,34 @@ def escape_text(unescaped_text): return escaped_text +def print_annotations(annotations): + for annotation in annotations: + print "<annotation name=" + annotation[0] + ">" + \ + escape_text(annotation[1]) + "</annotation>" + if __name__ == '__main__': try: - opts, args = getopt.getopt(sys.argv[1:], "d:s:o:", - ["source-dir="]) + opts, args = getopt.getopt(sys.argv[1:], "d:s:o:api", + ["source-dir=", "with-annotations", + "with-properties", "with-signals"]) except getopt.error, e: - sys.stderr.write('docgen.py: %s\n' % e) - sys.stderr.write( - 'usage: docgen.py [-s /src/dir]\n') - sys.exit(1) + sys.stderr.write('docextract_to_xml.py: %s\n' % e) + usage() 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: - sys.stderr.write( - 'usage: docgen.py [-s /src/dir]\n') - sys.exit(1) + usage() docs = docextract.extract(source_dirs); docextract.extract_tmpl(source_dirs, docs); #Try the tmpl sgml files too. @@ -58,25 +76,50 @@ if __name__ == '__main__': print "<root>" for name, value in docs.items(): - print "<function name=\"" + escape_text(name) + "\">" + # 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 "<description>" - #The value is a docextract.FunctionDoc - print escape_text(value.description) + print escape_text(value.get_description()) print "</description>" - # Loop through the parameters: - print "<parameters>" - for name, description in value.params: - print "<parameter name=\"" + escape_text(name) + "\">" - print "<parameter_description>" + escape_text(description) + "</parameter_description>" - print "</parameter>" + # Loop through the parameters if not dealing with a property: + if block_type != 'property': + print "<parameters>" + for name, description, annotations in value.params: + print "<parameter name=\"" + escape_text(name) + "\">" + print "<parameter_description>" + escape_text(description) + "</parameter_description>" + + if with_annotations: + print_annotations(annotations) + + print "</parameter>" + + print "</parameters>" - print "</parameters>" + # Show the return-type (also if not dealing with a property): + if with_annotations: + print "<return>" + print "<return_description>" + escape_text(value.ret[0]) + \ + "</return_description>" + print_annotations(value.ret[1]) + print "</return>" + else: + print "<return>" + escape_text(value.ret[0]) + "</return>" - # Show the return-type: - print "<return>" + escape_text(value.ret) + "</return>" + if with_annotations: + print_annotations(value.get_annotations()) - print "</function>\n" + print "</" + block_type + ">\n" print "</root>" |