Asterisk - The Open Source Telephony Project GIT-master-3dee037
Functions
post_process_documentation Namespace Reference

Functions

def collapse_event_pair (managerEventOne, managerEventTwo)
 
def collapse_manager_events (rootNode, managerEvents)
 
def main (argv=None)
 
def merge_parameter_information (managerEvent)
 

Function Documentation

◆ collapse_event_pair()

def collapse_event_pair (   managerEventOne,
  managerEventTwo 
)

Definition at line 49 of file post_process_documentation.py.

49def collapse_event_pair(managerEventOne, managerEventTwo):
50 # Move all children of managerEventTwo to managerEventOne
51 for node in managerEventTwo.childNodes:
52 managerEventOne.appendChild(node.cloneNode(True))
53
54 return managerEventOne
55
56
def collapse_event_pair(managerEventOne, managerEventTwo)

Referenced by collapse_manager_events().

◆ collapse_manager_events()

def collapse_manager_events (   rootNode,
  managerEvents 
)

Definition at line 57 of file post_process_documentation.py.

57def collapse_manager_events(rootNode, managerEvents):
58 events = {}
59 for managerEvent in managerEvents:
60 if (managerEvent.parentNode.nodeName == 'list-elements'
61 or managerEvent.parentNode.nodeName == 'responses'):
62 continue
63 managerEvent.parentNode.removeChild(managerEvent)
64 attr = managerEvent.getAttribute('name')
65 if attr in events:
66 # match, collapse the two managerEvents
67 events[attr] = collapse_event_pair(events[attr], managerEvent)
68 else:
69 events[attr] = managerEvent
70
71 # Combine parameter information and re-add the manager Events
72 for k, event in events.items():
74 rootNode.appendChild(event)
75 return
76
77
def collapse_manager_events(rootNode, managerEvents)

References collapse_event_pair(), and merge_parameter_information().

Referenced by main().

◆ main()

def main (   argv = None)

Definition at line 78 of file post_process_documentation.py.

78def main(argv=None):
79
80 if argv is None:
81 argv = sys.argv
82
83 parser = optparse.OptionParser()
84 parser.add_option('-i', '--input', dest='input_file',
85 default='doc/core-full-en_US.xml',
86 help='The XML file to process')
87 parser.add_option('-o', '--output', dest='output_file',
88 default='doc/core-en_US.xml',
89 help='The XML file to create')
90 (options, args) = parser.parse_args(argv)
91
92 dom = parse(options.input_file)
93
94 datasource = open(options.output_file, 'w')
95 docs = dom.getElementsByTagName("docs")[0]
96 managerEvents = dom.getElementsByTagName("managerEvent")
97 if (managerEvents):
98 collapse_manager_events(docs, managerEvents)
99
100 dom.writexml(datasource)
101 datasource.close()
102
103 return 0
104

References collapse_manager_events(), and main().

Referenced by main().

◆ merge_parameter_information()

def merge_parameter_information (   managerEvent)
 Merge the parameter information across all managerEventInstances
within a managerEvent node 

Definition at line 17 of file post_process_documentation.py.

17def merge_parameter_information(managerEvent):
18 ''' Merge the parameter information across all managerEventInstances
19 within a managerEvent node '''
20
21 def __swap_parameter_documentation(one, two):
22 # See who has the better documentation and use it
23 if (one.hasChildNodes() and not two.hasChildNodes()):
24 two.parentNode.replaceChild(one.cloneNode(True), two)
25 elif (two.hasChildNodes() and not one.hasChildNodes()):
26 one.parentNode.replaceChild(two.cloneNode(True), one)
27
28 def __merge_parameter(param, other_instances):
29 # Compare the parameter to every other instance's set of parameters
30 for other in other_instances:
31 other_parameters = other.getElementsByTagName("parameter")
32 match = [p for p in other_parameters
33 if p.getAttribute('name') == param.getAttribute('name')]
34 if (match):
35 # See who has the better documentation and use it
36 __swap_parameter_documentation(param, match[0])
37
38 instances = managerEvent.getElementsByTagName("managerEventInstance")
39 merged = []
40 for instance in instances:
41 others = [i for i in instances if i != instance]
42 parameters = instance.getElementsByTagName("parameter")
43 for parameter in parameters:
44 if parameter not in merged:
45 merged.append(parameter)
46 __merge_parameter(parameter, others)
47
48

Referenced by collapse_manager_events().