parse_xml.py
Go to the documentation of this file.
1 import os
2 
3 from docs.doc_template import ClassDoc, Doc, Docs, FreeDoc
4 import os.path as path
5 import xml.etree.ElementTree as ET
6 
7 DOXYGEN_CONF = 'doxygen.conf'
8 
9 
10 def parse(input_path, output_path, quiet=False, generate_xml_flag=True):
11  '''Parse the files for documentation and store it in templates.
12 
13  Arguments:
14  input_path -- path to the input folder or file
15  output_path -- path to the output folder
16  quiet -- turn on/off the messages that are generated to standard output by
17  Doxygen (default = False)
18  generate_xml -- use Doxygen to generate xml (default = True)
19 
20  Returns:
21  A Docs template storing all the documentation in the input.
22  '''
23  if generate_xml_flag:
24  generate_xml(input_path, output_path, quiet)
25 
26  class_docs = {}
27  free_docs = {}
28 
29  for root, dirs, files in os.walk(output_path):
30  for f in files:
31  if f.endswith('.xml'):
32  file_path = path.join(root, f)
33  doc = init_doc(file_path)
34 
35  if isinstance(doc, ClassDoc):
36  class_docs[file_path] = doc
37 
38  return Docs(class_docs, free_docs)
39 
40 
41 def generate_xml(input_path, output_path, quiet=False):
42  '''Parse the file for documentation and output it as in an xml format'''
43  if not quiet:
44  print('--------------Generating XML--------------')
45 
46  input_path = path.relpath(input_path, os.getcwd())
47  conf_path = path.relpath(path.join(path.dirname(__file__), DOXYGEN_CONF))
48  output_path = path.relpath(output_path)
49 
50  if not path.isdir(output_path):
51  os.mkdir(output_path)
52 
53  command = '( cat {conf_path} ; echo "INPUT={input_path}" ; echo "OUTPUT_DIRECTORY={output_path}" ; echo "EXTRACT_ALL={quiet}" ) | doxygen -'.format(
54  conf_path=conf_path,
55  input_path=input_path,
56  output_path=output_path,
57  quiet='YES' if quiet else 'NO'
58  )
59 
60  os.system(command)
61 
62 
63 def categorize_xml(tree):
64  '''Determine the type of the object the xml tree represents.
65 
66  Arguments:
67  tree -- an xml tree or path to xml string
68  '''
69  if isinstance(tree, str):
70  tree = ET.parse(tree)
71 
72  first_compound_def = find_first_element_with_tag(tree, 'compounddef')
73 
74  if first_compound_def is None:
75  return first_compound_def
76 
77  return first_compound_def.get('kind')
78 
79 
80 def init_doc(file_path):
81  '''Initialize documentation given its type.
82 
83  Categorize the xml tree at file_path and initiliaze the corresponding doc
84  type with the xml tree and other relevant information.
85 
86  Arguments:
87  file_path -- path to the xml tree
88 
89  Returns:
90  An initialized Doc
91  '''
92  tree = ET.parse(file_path)
93 
94  category = categorize_xml(tree)
95 
96  if category == 'class':
97  return ClassDoc(tree)
98 
99 
101  if tree.getroot().tag == tag:
102  return tree.getroot()
103 
104  return tree.find('.//{}'.format(tag))
105 
106 
107 def find_all_elements(tree, name, tag):
108  return tree.find('.//{}'.format(tag))
109 
110 
111 def find_method_element_text(method, name):
112  element = method.find(name)
113 
114  if element is None:
115  return None
116 
117  out = '' if element.text is None else element.text
118 
119  for e in list(element):
120  out += e.text
121 
122  return out
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
format
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:226
list
Definition: pytypes.h:2166
parse_xml.find_all_elements
def find_all_elements(tree, name, tag)
Definition: parse_xml.py:107
parse_xml.init_doc
def init_doc(file_path)
Definition: parse_xml.py:80
isinstance
bool isinstance(handle obj)
Definition: pytypes.h:842
parse_xml.categorize_xml
def categorize_xml(tree)
Definition: parse_xml.py:63
parse_xml.parse
def parse(input_path, output_path, quiet=False, generate_xml_flag=True)
Definition: parse_xml.py:10
parse_xml.generate_xml
def generate_xml(input_path, output_path, quiet=False)
Definition: parse_xml.py:41
parse_xml.find_first_element_with_tag
def find_first_element_with_tag(tree, tag)
Definition: parse_xml.py:100
parse_xml.find_method_element_text
def find_method_element_text(method, name)
Definition: parse_xml.py:111


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:30