Asterisk - The Open Source Telephony Project  18.5.0
post_process_documentation.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 # vin: sw=3 et:
3 '''
4 Copyright (C) 2012, Digium, Inc.
5 Matt Jordan <[email protected]>
6 
7 This program is free software, distributed under the terms of
8 the GNU General Public License Version 2.
9 '''
10 
11 import sys
12 import optparse
13 
14 from xml.dom.minidom import parse
15 
16 
17 def 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 
49 def 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 
57 def 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 
78 def 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 
105 if __name__ == "__main__":
106  sys.exit(main() or 0)
def collapse_event_pair(managerEventOne, managerEventTwo)
def collapse_manager_events(rootNode, managerEvents)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872