]> sigrok.org Git - libsigrok.git/blame - bindings/swig/doc.py
python: Wrap session stop callback
[libsigrok.git] / bindings / swig / doc.py
CommitLineData
bd4fda24
ML
1##
2## This file is part of the libsigrok project.
3##
4## Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
5##
6## This program is free software: you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation, either version 3 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program. If not, see <http://www.gnu.org/licenses/>.
18##
19
8fa3fc7c 20from __future__ import print_function
bd4fda24
ML
21from xml.etree import ElementTree
22import sys, os
23
24language, input_file = sys.argv[1:]
25input_dir = os.path.dirname(input_file)
26
27index = ElementTree.parse(input_file)
28
29def get_text(node):
30 paras = node.findall('para')
31 return str.join('\n\n', [p.text.rstrip() for p in paras if p.text])
32
33for compound in index.findall('compound'):
34 if compound.attrib['kind'] != 'class':
35 continue
36 class_name = compound.find('name').text
37 if not class_name.startswith('sigrok::'):
38 continue
39 doc = ElementTree.parse("%s/%s.xml" % (input_dir, compound.attrib['refid']))
40 cls = doc.find('compounddef')
41 brief = get_text(cls.find('briefdescription'))
42 if brief:
43 if language == 'python':
8fa3fc7c 44 print('%%feature("docstring") %s "%s";' % (class_name, brief))
bd4fda24 45 elif language == 'java':
8fa3fc7c
ML
46 print('%%typemap(javaclassmodifiers) %s "/** %s */\npublic class"' % (
47 class_name, brief))
bd4fda24
ML
48 for section in cls.findall('sectiondef'):
49 if section.attrib['kind'] != 'public-func':
50 continue
51 for function in section.findall('memberdef'):
52 function_name = function.find('name').text
53 brief = get_text(function.find('briefdescription'))
5cad31c7
ML
54 parameters = {}
55 for para in function.find('detaileddescription').findall('para'):
56 paramlist = para.find('parameterlist')
57 if paramlist is not None:
58 for param in paramlist.findall('parameteritem'):
59 namelist = param.find('parameternamelist')
60 name = namelist.find('parametername').text
61 description = get_text(param.find('parameterdescription'))
62 if description:
63 parameters[name] = description
bd4fda24
ML
64 if brief:
65 if language == 'python':
8fa3fc7c 66 print(str.join('\n', [
5cad31c7
ML
67 '%%feature("docstring") %s::%s "%s' % (
68 class_name, function_name, brief)] + [
69 '@param %s %s' % (name, desc)
8fa3fc7c 70 for name, desc in parameters.items()]) + '";')
bd4fda24 71 elif language == 'java':
8fa3fc7c 72 print(str.join('\n', [
5cad31c7
ML
73 '%%javamethodmodifiers %s::%s "/** %s' % (
74 class_name, function_name, brief)] + [
75 ' * @param %s %s' % (name, desc)
8fa3fc7c 76 for name, desc in parameters.items()]) + ' */\npublic"')