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/imgcodecs/include/opencv2/imgcodecs.hpp",
18 "../modules/videoio/include/opencv2/videoio.hpp",
19 "../modules/highgui/include/opencv2/highgui.hpp",
22 opencv_module_list = [
35 class RSTParser(object):
40 # reads the file containing functions and classes that do not need to be documented
41 def read_whitelist(self):
44 wf = open("check_docs_whitelist.txt", "rt")
47 self.parser = hp.CppHeaderParser()
49 for l in wf.readlines():
58 l = l.replace("cv::", "")
59 rst_decl = self.parser.parse_func_decl_no_wrap(l)
62 fname = l.replace("::", ".")
63 complist = fname.split(".")
68 prefix = (prefix + "." + c).lstrip(".")
69 wl = self.whitelist.get(prefix, [])
75 self.whitelist[fname] = "*"
78 self.whitelist[fname] = wl
81 def process_rst(self, docname):
82 df = open(docname, "rt")
87 for l in df.readlines():
91 if not ll.startswith(".. c:function::") and \
92 not ll.startswith(".. cpp:function::") and \
93 not ll.startswith(".. ocv:function::") and \
94 not ll.startswith(".. ocv:cfunction::"):
96 fdecl = ll[ll.find("::") + 3:]
99 balance = fdecl.count("(") - fdecl.count(")")
103 rst_decl = self.parser.parse_func_decl_no_wrap(fdecl)
105 hdr_decls = self.fmap.get(fname, [])
107 fname = fname.replace("cv.", "")
108 hdr_decls = self.fmap.get(fname, [])
110 print "Documented function %s (%s) in %s:%d is not in the headers" % (fdecl, rst_decl[0].replace(".", "::"), docname, lineno)
114 if len(hd[3]) != len(rst_decl[3]):
119 if a[0] != rst_decl[3][idx][0] and a[0].replace("cv::", "") != rst_decl[3][idx][0]:
122 if idx == len(hd[3]):
125 if decl_idx < len(hdr_decls):
126 self.fmap[fname] = hdr_decls[:decl_idx] + hdr_decls[decl_idx+1:]
128 print "Documented function %s in %s:%d does not have a match" % (fdecl, docname, lineno)
131 def decl2str(self, decl):
132 return "%s %s(%s)" % (decl[1], decl[0], ", ".join([a[0] + " " + a[1] for a in decl[3]]))
134 def check_module_docs(self, name):
135 self.parser = hp.CppHeaderParser()
139 for hname in opencv_hdr_list:
140 if hname.startswith("../modules/" + name):
141 decls += self.parser.parse(hname, wmode=False)
145 if not fname.startswith("struct") and not fname.startswith("class") and not fname.startswith("const"):
146 dlist = self.fmap.get(fname, [])
148 self.fmap[fname] = dlist
150 self.missing_docfunc_list = []
152 doclist = glob.glob("../modules/" + name + "/doc/*.rst")
156 print "\n\n########## The list of undocumented functions: ###########\n\n"
158 fkeys = sorted(self.fmap.keys())
160 # skip undocumented destructors
164 fcomps = f.split(".")
168 prefix = (prefix + "." + c).lstrip(".")
169 wlist_decls = self.whitelist.get(prefix, [])
170 if wlist_decls == "*":
172 if wlist_decls == "*":
174 wlist_decls = [self.decl2str(d) for d in wlist_decls]
177 dstr = self.decl2str(d)
178 # special hack for ML: skip old variants of the methods
179 if name == "ml" and ("CvMat" in dstr):
181 if dstr not in wlist_decls:
183 print "%s %s(%s)" % (d[1], d[0].replace(".", "::"), ", ".join([a[0] + " " + a[1] for a in d[3]]))
184 print "\n\n\nundocumented functions in %s: %d" % (name, misscount)
188 for m in opencv_module_list:
189 print "\n\n*************************** " + m + " *************************\n"
190 p.check_module_docs(m)