mirror of https://github.com/opencv/opencv.git
parent
d715badbde
commit
6174f62710
5 changed files with 276 additions and 206 deletions
@ -0,0 +1,101 @@ |
||||
""" |
||||
This code adds Python/Java signatures to the docs. |
||||
|
||||
TODO: Do the same thing for Java |
||||
* using javadoc/ get all the methods/classes/constants to a json file |
||||
|
||||
TODO: |
||||
* clarify when there are several C++ signatures corresponding to a single Python function. |
||||
i.e: calcHist(): |
||||
http://docs.opencv.org/3.2.0/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d |
||||
* clarify special case: |
||||
http://docs.opencv.org/3.2.0/db/de0/group__core__utils.html#ga4910d7f86336cd4eff9dd05575667e41 |
||||
""" |
||||
from __future__ import print_function |
||||
import os |
||||
import re |
||||
import sys |
||||
import logging |
||||
import html_functions |
||||
import doxygen_scan |
||||
|
||||
loglevel=os.environ.get("LOGLEVEL", None) |
||||
if loglevel: |
||||
logging.basicConfig(level=loglevel) |
||||
|
||||
|
||||
ROOT_DIR = sys.argv[1] |
||||
PYTHON_SIGNATURES_FILE = sys.argv[2] |
||||
JAVA_PYTHON = sys.argv[3] |
||||
|
||||
ADD_JAVA = False |
||||
ADD_PYTHON = False |
||||
if JAVA_PYTHON == "python": |
||||
ADD_PYTHON = True |
||||
|
||||
import json |
||||
python_signatures = dict() |
||||
with open(PYTHON_SIGNATURES_FILE, "rt") as f: |
||||
python_signatures = json.load(f) |
||||
print("Loaded Python signatures: %d" % len(python_signatures)) |
||||
|
||||
# only name -> class |
||||
# name and ret -> constant |
||||
# name, ret, arg-> function / class method |
||||
|
||||
class Configuration(): |
||||
def __init__(self): |
||||
self.ADD_PYTHON = ADD_PYTHON |
||||
self.python_signatures = python_signatures |
||||
self.ADD_JAVA = ADD_JAVA |
||||
|
||||
config = Configuration() |
||||
|
||||
import xml.etree.ElementTree as ET |
||||
root = ET.parse(ROOT_DIR + 'opencv.tag') |
||||
files_dict = dict() |
||||
|
||||
# constants and function from opencv.tag |
||||
namespaces = root.findall("./compound[@kind='namespace']") |
||||
#print("Found {} namespaces".format(len(namespaces))) |
||||
for ns in namespaces: |
||||
ns_name = ns.find("./name").text |
||||
#print('NS: {}'.format(ns_name)) |
||||
|
||||
files_dict = doxygen_scan.scan_namespace_constants(ns, ns_name, files_dict) |
||||
files_dict = doxygen_scan.scan_namespace_functions(ns, ns_name, files_dict) |
||||
|
||||
# class methods from opencv.tag |
||||
classes = root.findall("./compound[@kind='class']") |
||||
#print("Found {} classes".format(len(classes))) |
||||
for c in classes: |
||||
c_name = c.find("./name").text |
||||
name = ns_name + '::' + c_name |
||||
file = c.find("./filename").text |
||||
#print('Class: {} => {}'.format(name, file)) |
||||
files_dict = doxygen_scan.scan_class_methods(c, c_name, files_dict) |
||||
|
||||
# test |
||||
for file in files_dict: |
||||
soup = html_functions.load_html_file(ROOT_DIR + file) |
||||
if file == "d4/d86/group__imgproc__filter.html":#"d4/d86/group__imgproc__filter.html": |
||||
anchor_list = files_dict[file] |
||||
counter = 0 |
||||
anchor_tmp_list = [] |
||||
for anchor in anchor_list: |
||||
counter += 1 |
||||
# if the next anchor shares the same C++ name (= same method/function), join them together |
||||
if counter < len(anchor_list) and anchor_list[counter].cppname == anchor.cppname: |
||||
anchor_tmp_list.append(anchor) |
||||
continue |
||||
else: |
||||
anchor_tmp_list.append(anchor) |
||||
# check if extists a python equivalent signature |
||||
for signature in python_signatures: # signature is a key with the C++ name |
||||
if signature == anchor.cppname: # if available name in python |
||||
# they should also have the same type |
||||
soup = html_functions.append_python_signature(python_signatures[signature], anchor_tmp_list, soup) |
||||
#print(signature) |
||||
# reset anchor temporary list |
||||
anchor_tmp_list[:] = [] |
||||
html_functions.update_html(ROOT_DIR + file, soup) |
@ -0,0 +1,51 @@ |
||||
class Anchor(object): |
||||
anchor = "" |
||||
type = "" |
||||
cppname = "" |
||||
|
||||
def __init__(self, anchor, type, cppname): |
||||
self.anchor = anchor |
||||
self.type = type |
||||
self.cppname = cppname |
||||
|
||||
def add_to_file(files_dict, file, anchor): |
||||
if file in files_dict: |
||||
# if that file already exists as a key in the dictionary |
||||
files_dict[file].append(anchor) |
||||
else: |
||||
files_dict[file] = [anchor] |
||||
return files_dict |
||||
|
||||
|
||||
def scan_namespace_constants(ns, ns_name, files_dict): |
||||
constants = ns.findall("./member[@kind='enumvalue']") |
||||
for c in constants: |
||||
c_name = c.find("./name").text |
||||
name = ns_name + '::' + c_name |
||||
file = c.find("./anchorfile").text |
||||
anchor = c.find("./anchor").text |
||||
#print(' CONST: {} => {}#{}'.format(name, file, anchor)) |
||||
files_dict = add_to_file(files_dict, file, Anchor(anchor, "const", name)) |
||||
return files_dict |
||||
|
||||
def scan_namespace_functions(ns, ns_name, files_dict): |
||||
functions = ns.findall("./member[@kind='function']") |
||||
for f in functions: |
||||
f_name = f.find("./name").text |
||||
name = ns_name + '::' + f_name |
||||
file = f.find("./anchorfile").text |
||||
anchor = f.find("./anchor").text |
||||
#print(' FN: {} => {}#{}'.format(name, file, anchor)) |
||||
files_dict = add_to_file(files_dict, file, Anchor(anchor, "fn", name)) |
||||
return files_dict |
||||
|
||||
def scan_class_methods(c, c_name, files_dict): |
||||
methods = c.findall("./member[@kind='function']") |
||||
for m in methods: |
||||
m_name = m.find("./name").text |
||||
name = c_name + '::' + m_name |
||||
file = m.find("./anchorfile").text |
||||
anchor = m.find("./anchor").text |
||||
#print(' Method: {} => {}#{}'.format(name, file, anchor)) |
||||
files_dict = add_to_file(files_dict, file, Anchor(anchor, "method", name)) |
||||
return files_dict |
@ -1,58 +0,0 @@ |
||||
""" |
||||
This code adds Python signatures to the docs. |
||||
|
||||
TODO: |
||||
* clarify when there are several C++ signatures corresponding to a single Python function. |
||||
i.e: calcHist(): |
||||
http://docs.opencv.org/3.2.0/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d |
||||
* clarify special case: |
||||
http://docs.opencv.org/3.2.0/db/de0/group__core__utils.html#ga4910d7f86336cd4eff9dd05575667e41 |
||||
""" |
||||
from __future__ import print_function |
||||
import os |
||||
import re |
||||
import sys |
||||
import logging |
||||
|
||||
loglevel=os.environ.get("LOGLEVEL", None) |
||||
if loglevel: |
||||
logging.basicConfig(level=loglevel) |
||||
|
||||
ADD_JAVA = False |
||||
ADD_PYTHON = True |
||||
ROOT_DIR = sys.argv[1] |
||||
PYTHON_SIGNATURES_FILE = sys.argv[2] |
||||
|
||||
import json |
||||
python_signatures = dict() |
||||
with open(PYTHON_SIGNATURES_FILE, "rt") as f: |
||||
python_signatures = json.load(f) |
||||
print("Loaded Python signatures: %d" % len(python_signatures)) |
||||
|
||||
class Configuration(): |
||||
def __init__(self): |
||||
self.ADD_PYTHON = ADD_PYTHON |
||||
self.python_signatures = python_signatures |
||||
self.ADD_JAVA = ADD_JAVA |
||||
|
||||
config = Configuration() |
||||
|
||||
|
||||
import html_functions |
||||
|
||||
soup = html_functions.load_html_file(ROOT_DIR + "index.html") |
||||
href_list = html_functions.get_links_list(soup, True) |
||||
|
||||
for link in href_list: |
||||
# add python signatures to the module |
||||
soup = html_functions.load_html_file(ROOT_DIR + link) |
||||
sub_href_list = html_functions.get_links_list(soup, True) |
||||
module_name = html_functions.get_text_between_substrings(link, "group__", ".html") |
||||
html_functions.add_signatures(soup, ROOT_DIR + link, module_name, config) |
||||
|
||||
# add python signatures to the sub-modules |
||||
link = re.sub(r"group__.+html", "", link) |
||||
for sub_link in sub_href_list: |
||||
tmp_dir = ROOT_DIR + link + sub_link |
||||
soup = html_functions.load_html_file(tmp_dir) |
||||
html_functions.add_signatures(soup, tmp_dir, module_name, config) |
Loading…
Reference in new issue