|
| 1 | +""" |
| 2 | +This code adds Python/Java signatures to the docs. |
| 3 | +
|
| 4 | +TODO: Do the same thing for Java |
| 5 | +* using javadoc/ get all the methods/classes/constants to a json file |
| 6 | +
|
| 7 | +TODO: |
| 8 | +* clarify when there are several C++ signatures corresponding to a single Python function. |
| 9 | + i.e: calcHist(): |
| 10 | + http://docs.opencv.org/3.2.0/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d |
| 11 | +* clarify special case: |
| 12 | + http://docs.opencv.org/3.2.0/db/de0/group__core__utils.html#ga4910d7f86336cd4eff9dd05575667e41 |
| 13 | +""" |
| 14 | +from __future__ import print_function |
| 15 | +import os |
| 16 | +import re |
| 17 | +import sys |
| 18 | +import logging |
| 19 | +import html_functions |
| 20 | +import doxygen_scan |
| 21 | + |
| 22 | +loglevel=os.environ.get("LOGLEVEL", None) |
| 23 | +if loglevel: |
| 24 | + logging.basicConfig(level=loglevel) |
| 25 | + |
| 26 | + |
| 27 | +ROOT_DIR = sys.argv[1] |
| 28 | +PYTHON_SIGNATURES_FILE = sys.argv[2] |
| 29 | +JAVA_PYTHON = sys.argv[3] |
| 30 | + |
| 31 | +ADD_JAVA = False |
| 32 | +ADD_PYTHON = False |
| 33 | +if JAVA_PYTHON == "python": |
| 34 | + ADD_PYTHON = True |
| 35 | + |
| 36 | +import json |
| 37 | +python_signatures = dict() |
| 38 | +with open(PYTHON_SIGNATURES_FILE, "rt") as f: |
| 39 | + python_signatures = json.load(f) |
| 40 | + print("Loaded Python signatures: %d" % len(python_signatures)) |
| 41 | + |
| 42 | +# only name -> class |
| 43 | +# name and ret -> constant |
| 44 | +# name, ret, arg-> function / class method |
| 45 | + |
| 46 | +class Configuration(): |
| 47 | + def __init__(self): |
| 48 | + self.ADD_PYTHON = ADD_PYTHON |
| 49 | + self.python_signatures = python_signatures |
| 50 | + self.ADD_JAVA = ADD_JAVA |
| 51 | + |
| 52 | +config = Configuration() |
| 53 | + |
| 54 | +import xml.etree.ElementTree as ET |
| 55 | +root = ET.parse(ROOT_DIR + 'opencv.tag') |
| 56 | +files_dict = dict() |
| 57 | + |
| 58 | +# constants and function from opencv.tag |
| 59 | +namespaces = root.findall("./compound[@kind='namespace']") |
| 60 | +#print("Found {} namespaces".format(len(namespaces))) |
| 61 | +for ns in namespaces: |
| 62 | + ns_name = ns.find("./name").text |
| 63 | + #print('NS: {}'.format(ns_name)) |
| 64 | + |
| 65 | + files_dict = doxygen_scan.scan_namespace_constants(ns, ns_name, files_dict) |
| 66 | + files_dict = doxygen_scan.scan_namespace_functions(ns, ns_name, files_dict) |
| 67 | + |
| 68 | +# class methods from opencv.tag |
| 69 | +classes = root.findall("./compound[@kind='class']") |
| 70 | +#print("Found {} classes".format(len(classes))) |
| 71 | +for c in classes: |
| 72 | + c_name = c.find("./name").text |
| 73 | + name = ns_name + '::' + c_name |
| 74 | + file = c.find("./filename").text |
| 75 | + #print('Class: {} => {}'.format(name, file)) |
| 76 | + files_dict = doxygen_scan.scan_class_methods(c, c_name, files_dict) |
| 77 | + |
| 78 | +# test |
| 79 | +for file in files_dict: |
| 80 | + soup = html_functions.load_html_file(ROOT_DIR + file) |
| 81 | + if file == "d4/d86/group__imgproc__filter.html":#"d4/d86/group__imgproc__filter.html": |
| 82 | + anchor_list = files_dict[file] |
| 83 | + counter = 0 |
| 84 | + anchor_tmp_list = [] |
| 85 | + for anchor in anchor_list: |
| 86 | + counter += 1 |
| 87 | + # if the next anchor shares the same C++ name (= same method/function), join them together |
| 88 | + if counter < len(anchor_list) and anchor_list[counter].cppname == anchor.cppname: |
| 89 | + anchor_tmp_list.append(anchor) |
| 90 | + continue |
| 91 | + else: |
| 92 | + anchor_tmp_list.append(anchor) |
| 93 | + # check if extists a python equivalent signature |
| 94 | + for signature in python_signatures: # signature is a key with the C++ name |
| 95 | + if signature == anchor.cppname: # if available name in python |
| 96 | + # they should also have the same type |
| 97 | + soup = html_functions.append_python_signature(python_signatures[signature], anchor_tmp_list, soup) |
| 98 | + #print(signature) |
| 99 | + # reset anchor temporary list |
| 100 | + anchor_tmp_list[:] = [] |
| 101 | + html_functions.update_html(ROOT_DIR + file, soup) |
0 commit comments