metadoc.py 2.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/python

# Copyright (C) 2017 Belledonne Communications SARL
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


class Nil:
	pass


class Reference:
	def __init__(self, name):
		self.cObjectName = name


class Paragraph:
	def __init__(self, node=None):
		self.parts = []
		if node is not None:
			self.parse_doxygen_node(node)
	
	def parse_doxygen_node(self, node):
		for partNode in node.iter():
			text = partNode.text
			if text is not None:
				self.parts.append(text)
			if partNode is not node:
				tail = partNode.tail
				if tail is not None:
					self.parts.append(tail)


class Description:
	def __init__(self, node=None):
		self.paragraphs = []
		if node is not None:
			self.parse_doxygen_node(node)
	
	def parse_doxygen_node(self, node):
		for paraNode in node.findall('./para'):
			self.paragraphs.append(Paragraph(paraNode))


class Translator:
	def translate(self, description):
59 60 61
		if description is None:
			return None
		
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
		lines = []
		for para in description.paragraphs:
			if para is not description.paragraphs[0]:
				lines.append('')
			lines.append(''.join(para.parts))
		
		self._tag_as_brief(lines)
		
		translatedDoc = {'lines': []}
		for line in lines:
			translatedDoc['lines'].append({'line': line})
			
		return translatedDoc


class DoxygenCppTranslator(Translator):
	def _tag_as_brief(self, lines):
		if len(lines) > 0:
			lines[0] = '@brief ' + lines[0]


class SandcastleCSharpTranslator(Translator):
	def _tag_as_brief(self, lines):
		if len(lines) > 0:
			lines[0] = '<summary>' + lines[0]
			lines[-1] = lines[-1] + '</summary>'