Improved javadoc generation scripts

This commit is contained in:
Andrey Kamaev 2012-04-28 12:31:53 +00:00
parent b165997e22
commit 50009e1546
2 changed files with 55 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import os, sys, re, string, glob
allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts", "photo"]
allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts", "photo", "videostab"]
verbose = False
show_warnings = True
show_errors = True
@ -67,14 +67,47 @@ class JavadocGenerator(object):
inf.close()
outf.close()
def FinishParagraph(self, text):
return text[:-1] + "</p>\n"
def ReformatForJavadoc(self, s):
out = ""
in_paragraph = False
in_list = False
for term in s.split("\n"):
if term.startswith("*") or term.startswith("#."):
term = " " + term
in_list_item = False
if term.startswith("*"):
in_list_item = True
if in_paragraph:
out = self.FinishParagraph(out)
in_paragraph = False
if not in_list:
out += " * <ul>\n"
in_list = True
term = " <li>" + term[1:]
if term.startswith("#."):
in_list_item = True
if in_paragraph:
out = self.FinishParagraph(out)
in_paragraph = False
if not in_list:
out += " * <ul>\n"
in_list = True
term = " <li>" + term[2:]
if not term:
if in_paragraph:
out = self.FinishParagraph(out)
in_paragraph = False
out += " *\n"
else:
if in_list and not in_list_item:
in_list = False
if out.endswith(" *\n"):
out = out[:-3] + " * </ul>\n *\n"
else:
out += " * </ul>\n"
pos_start = 0
pos_end = min(77, len(term)-1)
while pos_start < pos_end:
@ -91,12 +124,22 @@ class JavadocGenerator(object):
pos_end += 1
else:
break
out += " * " + term[pos_start:pos_end+1].rstrip() + "\n"
if in_paragraph or term.startswith("@") or in_list_item:
out += " * "
else:
in_paragraph = True
out += " * <p>"
out += term[pos_start:pos_end+1].rstrip() + "\n"
pos_start = pos_end + 1
pos_end = min(pos_start + 77, len(term)-1)
if in_paragraph:
out = self.FinishParagraph(out)
if in_list:
out += " * </ul>\n"
return out
def getJavaName(self, decl):
def getJavaName(self, decl, methodSeparator = "."):
name = "org.opencv."
name += decl["module"]
if "class" in decl:
@ -104,11 +147,11 @@ class JavadocGenerator(object):
else:
name += "." + decl["module"].capitalize()
if "method" in decl:
name += "." + decl["method"]
name += methodSeparator + decl["method"]
return name
def getDocURL(self, decl):
url = "http://opencv.itseez.com/modules/"
url = "http://docs.opencv.org/modules/"
url += decl["module"]
url += "/doc/"
url += os.path.basename(decl["file"]).replace(".rst",".html")
@ -168,7 +211,7 @@ class JavadocGenerator(object):
for see in decl["seealso"]:
seedecl = self.definitions.get(see,None)
if seedecl:
doc += prefix + " * @see " + self.getJavaName(seedecl) + "\n"
doc += prefix + " * @see " + self.getJavaName(seedecl, "#") + "\n"
else:
doc += prefix + " * @see " + see.replace("::",".") + "\n"
prefix = " *\n"

View File

@ -499,7 +499,8 @@ class RstParser(object):
def normalizeText(self, s):
if s is None:
return s
s = re.sub(r"\.\. math::[ ]*\n+(.*?)(\n[ ]*\n|$)", mathReplace2, s)
s = re.sub(r"\.\. math::[ \r]*\n+((.|\n)*?)(\n[ \r]*\n|$)", mathReplace2, s)
s = re.sub(r":math:`([^`]+?)`", mathReplace, s)
s = re.sub(r" *:sup:", "^", s)
@ -574,6 +575,7 @@ class RstParser(object):
s = re.sub(r"[\n ]+\.", ".", s)
s = s.replace("**", "")
s = re.sub(r"``([^\n]+?)``", "<code>\\1</code>", s)
s = s.replace("``", "\"")
s = s.replace("`", "\"")
s = s.replace("\"\"", "\"")
@ -688,7 +690,7 @@ def mathReplace(match):
m = m.replace("}", ")")
#print "%s ===> %s" % (match.group(0), m)
return m
return "<em>" + m + "</em>"
if __name__ == "__main__":
if len(sys.argv) < 2: