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.
16 if "ast_manager_event_multichan" in candidate_string:
18 elif "ast_manager_event" in candidate_string:
19 return "ast_manager_event"
20 elif "manager_event" in candidate_string:
21 return "manager_event"
26 ''' Parse the information for a manager event
29 xml_fragment The XML fragment comment
32 A well-formed XML fragment containing the comments passed in,
as well
as
33 information obtained
from the manager_event macro calls
36 def __node_contains_parameter(node, parameter):
37 ''' Return whether or not a node contains a given parameter name '''
38 return any([n
for n
in node.getElementsByTagName(
"parameter")
39 if __node_contains_attribute(n, parameter)])
41 def __node_contains_attribute(node, attribute_name):
42 ''' Return whether or not a node contains a given attribute name '''
43 return any([attr
for attr
in node.attributes.items()
44 if attr[1] == attribute_name])
51 for line
in sys.stdin:
53 candidate_lines.append(line)
57 candidate_string =
''.join(candidate_lines)
61 return ''.join(xml_fragment)
64 first_paren = candidate_string.index(
"(", 0)
65 last_paren = candidate_string.rindex(
");")
66 candidate_string = candidate_string[first_paren + 1:last_paren]
69 func_parameter_tokens = candidate_string.split(
',')
71 if type ==
"manager_event" or type ==
"multichan":
72 class_level = func_parameter_tokens[0].strip()
73 event_type = func_parameter_tokens[1].strip()
75 class_level = func_parameter_tokens[1].strip()
76 event_type = func_parameter_tokens[2].strip()
78 if type ==
"manager_event":
79 event_parameters = func_parameter_tokens[2].strip()
80 elif type ==
"ast_manager_event":
81 event_parameters = func_parameter_tokens[3].strip()
83 event_parameters = func_parameter_tokens[4].strip()
85 parameter_tokens = event_parameters.replace(
"\"",
"").split(
'\\r\\n')
89 node_text =
'<managerEvent language=\"%s\" name=\"%s\" xmlns:xi=\"%s\">'
90 xml_fragment.insert(0, node_text % (
'en_US',
91 event_type.strip().
replace(
"\"",
""),
92 'http://www.w3.org/2001/XInclude'))
93 xml_fragment[1] =
"<managerEventInstance class=\"%s\">" % (class_level)
94 xml_fragment.insert(
len(xml_fragment),
"</managerEvent>")
97 dom = xml.dom.minidom.parseString(
''.join(xml_fragment))
100 instance = dom.getElementsByTagName(
"managerEventInstance")[0]
101 syntax = instance.getElementsByTagName(
"syntax")
103 syntax = dom.createElement(
"syntax")
104 instance.appendChild(syntax)
106 for node
in instance.getElementsByTagName(
"parameter"):
107 syntax.appendChild(node.cloneNode(
True))
108 instance.removeChild(node)
114 for parameter
in parameter_tokens:
115 if not len(parameter):
117 index = parameter.find(
':')
119 index =
len(parameter)
120 parameter = (parameter[:index].strip().
replace(
"\"",
""))
121 if (
'%s' not in parameter
and
122 not __node_contains_parameter(syntax, parameter)):
123 e = dom.createElement(
"parameter")
124 e.setAttribute(
'name', parameter)
125 syntax.appendChild(e)
127 return dom.toxml().
replace(
"<?xml version=\"1.0\" ?>",
"").
replace(
128 'xmlns:xi="http://www.w3.org/2001/XInclude"',
'')
141 for line
in sys.stdin:
149 if (
"/*** DOCUMENTATION" in line):
151 elif (
"***/" in line
and in_doc):
159 if "<managerEventInstance>" in xml_fragment[0]:
162 xml.append(
''.join(xml_fragment))
166 xml_fragment.append(
"%s\n" % line)
168 sys.stdout.write(
''.join(xml))
171if __name__ ==
"__main__":
172 sys.exit(
main()
or 0)
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
def get_manager_event_method_type(candidate_string)
def parse_manager_event_instance(xml_fragment)