File: parse_doxygen_xml.py

package info (click to toggle)
gtsam 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 46,108 kB
  • sloc: cpp: 127,191; python: 14,312; xml: 8,442; makefile: 252; sh: 119; ansic: 101
file content (78 lines) | stat: -rw-r--r-- 2,488 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import os.path as path
import xml.etree.ElementTree as ET

from docs.docs import ClassDoc, Doc, Docs, FreeDoc

DOXYGEN_CONF = 'doxygen.conf'


class ParseDoxygenXML():
    def __init__(self, input_path, output_path):
        """Parse the Doxygen generated XML files.

        Arguments:
        input_path -- path to the input folder or file
        output_path -- path to the output folder
        """
        self.input_path = input_path
        self.output_path = output_path

    def run(self, quiet=True):
        """Run the Doxygen XML parser.

        Arguments:
        quiet -- turn on/off the messages that are generated to standard
                 output by Doxygen (default = True)

        Returns:
            A Docs template storing all the class and free documentation in the
            file.
        """
        class_docs = {}
        free_docs = {}

        for root, dirs, files in os.walk(self.output_path):
            for f in files:
                if f.endswith('.xml'):
                    file_path = path.join(root, f)
                    tree = ET.parse(file_path)

                    if tree.getroot().tag == 'compounddef':
                        first_compound_def = tree.getroot()
                    else:
                        first_compound_def = tree.find(
                            './/{}'.format('compounddef'))

                    if first_compound_def is None:
                        continue

                    category = first_compound_def.get('kind')

                    if category == 'class':
                        class_docs[file_path] = ClassDoc(tree)

        return Docs(class_docs, free_docs)


# TODO: This should be done in the make file.
def generate_xml(input_path, output_path, quiet=False):
    '''Parse the file for documentation and output it as in an xml format'''
    if not quiet:
        print('--------------Generating XML--------------')

    input_path = path.relpath(input_path, os.getcwd())
    conf_path = path.relpath(path.join(path.dirname(__file__), DOXYGEN_CONF))
    output_path = path.relpath(output_path)

    if not path.isdir(output_path):
        os.mkdir(output_path)

    command = '( cat {conf_path} ; echo "INPUT={input_path}" ; echo "OUTPUT_DIRECTORY={output_path}" ; echo "EXTRACT_ALL={quiet}" ) | doxygen -'.format(
        conf_path=conf_path,
        input_path=input_path,
        output_path=output_path,
        quiet='YES' if quiet else 'NO'
    )

    os.system(command)