4Copyright (C) 2012, Digium, Inc.
5Matt Jordan <mjordan@digium.com>
7This program is free software, distributed under the terms of
8the GNU General Public License Version 2.
14from xml.dom.minidom
import parse
18 ''' Merge the parameter information across all managerEventInstances
19 within a managerEvent node '''
21 def __swap_parameter_documentation(one, two):
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)
28 def __merge_parameter(param, other_instances):
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')]
36 __swap_parameter_documentation(param, match[0])
38 instances = managerEvent.getElementsByTagName(
"managerEventInstance")
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)
51 for node
in managerEventTwo.childNodes:
52 managerEventOne.appendChild(node.cloneNode(
True))
54 return managerEventOne
59 for managerEvent
in managerEvents:
60 if (managerEvent.parentNode.nodeName ==
'list-elements'
61 or managerEvent.parentNode.nodeName ==
'responses'):
63 managerEvent.parentNode.removeChild(managerEvent)
64 attr = managerEvent.getAttribute(
'name')
69 events[attr] = managerEvent
72 for k, event
in events.items():
74 rootNode.appendChild(event)
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)
92 dom = parse(options.input_file)
94 datasource = open(options.output_file,
'w')
95 docs = dom.getElementsByTagName(
"docs")[0]
96 managerEvents = dom.getElementsByTagName(
"managerEvent")
100 dom.writexml(datasource)
105if __name__ ==
"__main__":
106 sys.exit(
main()
or 0)
def merge_parameter_information(managerEvent)
def collapse_event_pair(managerEventOne, managerEventTwo)
def collapse_manager_events(rootNode, managerEvents)