5 sys.path.append("../modules/python/src2/")
6 import hdr_parser as hp
9 "../modules/core/include/opencv2/core.hpp",
10 "../modules/ml/include/opencv2/ml.hpp",
11 "../modules/imgproc/include/opencv2/imgproc.hpp",
12 "../modules/calib3d/include/opencv2/calib3d.hpp",
13 "../modules/features2d/include/opencv2/features2d.hpp",
14 "../modules/video/include/opencv2/video/tracking.hpp",
15 "../modules/video/include/opencv2/video/background_segm.hpp",
16 "../modules/objdetect/include/opencv2/objdetect.hpp",
17 "../modules/highgui/include/opencv2/highgui.hpp",
20 opencv_module_list = [
31 class RSTParser(object):
36 # reads the file containing functions and classes that do not need to be documented
37 def read_whitelist(self):
40 wf = open("check_docs_whitelist.txt", "rt")
43 self.parser = hp.CppHeaderParser()
45 for l in wf.readlines():
54 l = l.replace("cv::", "")
55 rst_decl = self.parser.parse_func_decl_no_wrap(l)
58 fname = l.replace("::", ".")
59 complist = fname.split(".")
64 prefix = (prefix + "." + c).lstrip(".")
65 wl = self.whitelist.get(prefix, [])
71 self.whitelist[fname] = "*"
74 self.whitelist[fname] = wl
77 def process_rst(self, docname):
78 df = open(docname, "rt")
83 for l in df.readlines():
87 if not ll.startswith(".. c:function::") and \
88 not ll.startswith(".. cpp:function::") and \
89 not ll.startswith(".. ocv:function::") and \
90 not ll.startswith(".. ocv:cfunction::"):
92 fdecl = ll[ll.find("::") + 3:]
95 balance = fdecl.count("(") - fdecl.count(")")
99 rst_decl = self.parser.parse_func_decl_no_wrap(fdecl)
101 hdr_decls = self.fmap.get(fname, [])
103 fname = fname.replace("cv.", "")
104 hdr_decls = self.fmap.get(fname, [])
106 print "Documented function %s (%s) in %s:%d is not in the headers" % (fdecl, rst_decl[0].replace(".", "::"), docname, lineno)
110 if len(hd[3]) != len(rst_decl[3]):
115 if a[0] != rst_decl[3][idx][0] and a[0].replace("cv::", "") != rst_decl[3][idx][0]:
118 if idx == len(hd[3]):
121 if decl_idx < len(hdr_decls):
122 self.fmap[fname] = hdr_decls[:decl_idx] + hdr_decls[decl_idx+1:]
124 print "Documented function %s in %s:%d does not have a match" % (fdecl, docname, lineno)
127 def decl2str(self, decl):
128 return "%s %s(%s)" % (decl[1], decl[0], ", ".join([a[0] + " " + a[1] for a in decl[3]]))
130 def check_module_docs(self, name):
131 self.parser = hp.CppHeaderParser()
135 for hname in opencv_hdr_list:
136 if hname.startswith("../modules/" + name):
137 decls += self.parser.parse(hname, wmode=False)
141 if not fname.startswith("struct") and not fname.startswith("class") and not fname.startswith("const"):
142 dlist = self.fmap.get(fname, [])
144 self.fmap[fname] = dlist
146 self.missing_docfunc_list = []
148 doclist = glob.glob("../modules/" + name + "/doc/*.rst")
152 print "\n\n########## The list of undocumented functions: ###########\n\n"
154 fkeys = sorted(self.fmap.keys())
156 # skip undocumented destructors
160 fcomps = f.split(".")
164 prefix = (prefix + "." + c).lstrip(".")
165 wlist_decls = self.whitelist.get(prefix, [])
166 if wlist_decls == "*":
168 if wlist_decls == "*":
170 wlist_decls = [self.decl2str(d) for d in wlist_decls]
173 dstr = self.decl2str(d)
174 # special hack for ML: skip old variants of the methods
175 if name == "ml" and ("CvMat" in dstr):
177 if dstr not in wlist_decls:
179 print "%s %s(%s)" % (d[1], d[0].replace(".", "::"), ", ".join([a[0] + " " + a[1] for a in d[3]]))
180 print "\n\n\nundocumented functions in %s: %d" % (name, misscount)
184 for m in opencv_module_list:
185 print "\n\n*************************** " + m + " *************************\n"
186 p.check_module_docs(m)