[asterisk-commits] mjordan: branch mjordan/manager-events r368720 - /team/mjordan/manager-events...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 11 09:10:34 CDT 2012


Author: mjordan
Date: Mon Jun 11 09:10:30 2012
New Revision: 368720

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=368720
Log:
Address Russell's findings

Modified:
    team/mjordan/manager-events/build_tools/get_documentation.py
    team/mjordan/manager-events/build_tools/post_process_documentation.py

Modified: team/mjordan/manager-events/build_tools/get_documentation.py
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/manager-events/build_tools/get_documentation.py?view=diff&rev=368720&r1=368719&r2=368720
==============================================================================
--- team/mjordan/manager-events/build_tools/get_documentation.py (original)
+++ team/mjordan/manager-events/build_tools/get_documentation.py Mon Jun 11 09:10:30 2012
@@ -14,6 +14,7 @@
 
 from xml.dom.minidom import Element
 
+
 def get_manager_event_method_type(candidate_string):
     if "ast_manager_event_multichan" in candidate_string:
         return "multichan"
@@ -22,6 +23,7 @@
     elif "manager_event" in candidate_string:
         return "manager_event"
     return ""
+
 
 def parse_manager_event_instance(xml_fragment):
     ''' Parse the information for a manager event
@@ -34,18 +36,26 @@
     information obtained from the manager_event macro calls
     '''
 
+    def __node_contains_parameter(node, parameter):
+        ''' Return whether or not a node contains a given parameter name '''
+        return any([n for n in node.getElementsByTagName("parameter")
+                    if __node_contains_attribute(n, parameter)])
+
+    def __node_contains_attribute(node, attribute_name):
+        ''' Return whether or not a node contains a given attribute name '''
+        return any([attr for attr in node.attributes.items()
+                    if attr[1] == attribute_name])
+
     candidate_lines = []
     type = ""
 
     # Read the manager_event method call, which should occur after
     # the documentation block
-    while (True):
-        line = sys.stdin.readline()
-        line = line.strip()
-        if line:
+    for line in sys.stdin:
+        if len(line):
             candidate_lines.append(line)
         if ");" in line:
-            break;
+            break
 
     candidate_string = ''.join(candidate_lines)
     type = get_manager_event_method_type(candidate_string)
@@ -54,7 +64,10 @@
         return ''.join(xml_fragment)
 
     # strip off the macro name
-    candidate_string = candidate_string[candidate_string.index("(",0) + 1:candidate_string.rindex(");")]
+    first_paren = candidate_string.index("(", 0)
+    last_paren = candidate_string.rindex(");")
+    candidate_string = candidate_string[first_paren + 1:last_paren]
+
     # split into parameter tokens
     func_parameter_tokens = candidate_string.split(',')
 
@@ -76,8 +89,10 @@
 
     # Build the top level XML element information.  Note that we temporarily
     # add the xi namespace in case any includes are used
-    xml_fragment.insert(0, "<managerEvent language=\"%s\" name=\"%s\" xmlns:xi=\"http://www.w3.org/2001/XInclude\">" %
-                        ('en_US', event_type.strip().replace("\"","")))
+    node_text = '<managerEvent language=\"%s\" name=\"%s\" xmlns:xi=\"%s\">'
+    xml_fragment.insert(0, node_text % ('en_US',
+                                        event_type.strip().replace("\"", ""),
+                                        'http://www.w3.org/2001/XInclude'))
     xml_fragment[1] = "<managerEventInstance class=\"%s\">" % (class_level)
     xml_fragment.insert(len(xml_fragment), "</managerEvent>")
 
@@ -100,20 +115,21 @@
     # Add parameters found in the method invocation that were not previously
     # documented
     for parameter in parameter_tokens:
-        if not parameter:
+        if not len(parameter):
             continue
         index = parameter.find(':')
         if index < 0:
             index = len(parameter)
-        parameter = (parameter.strip().replace("\"",""))[:index]
-        if ('%s' not in parameter and 
-            not any([node for node in syntax.getElementsByTagName("parameter") if
-                any([attr for attr in node.attributes.items() if attr[1] == parameter])])):
+        parameter = (parameter[:index].strip().replace("\"", ""))
+        if ('%s' not in parameter and
+            not __node_contains_parameter(syntax, parameter)):
             e = dom.createElement("parameter")
             e.setAttribute('name', parameter)
             syntax.appendChild(e)
 
-    return dom.toxml().replace("<?xml version=\"1.0\" ?>", "").replace('xmlns:xi="http://www.w3.org/2001/XInclude"', '')
+    return dom.toxml().replace("<?xml version=\"1.0\" ?>", "").replace(
+               'xmlns:xi="http://www.w3.org/2001/XInclude"', '')
+
 
 def main(argv=None):
 
@@ -125,10 +141,9 @@
     xml = []
     line_number = 0
 
-    while(True):
+    for line in sys.stdin:
         # Note: multiple places may have to read a line, so iterating over
         # readlines isn't possible.  Break when a null line is returned
-        line = sys.stdin.readline()
         line_number += 1
         if not line:
             break
@@ -136,7 +151,7 @@
         line = line.strip()
         if ("/*** DOCUMENTATION" in line):
             in_doc = True
-        elif ("***/" in line and in_doc == True):
+        elif ("***/" in line and in_doc):
             # Depending on what we're processing, determine if we need to do
             # any additional work
             in_doc = False
@@ -150,11 +165,11 @@
                 xml.append(''.join(xml_fragment))
 
             xml_fragment = []
-        elif (in_doc == True):
+        elif (in_doc):
             xml_fragment.append("%s\n" % line)
 
     sys.stdout.write(''.join(xml))
     return 0
 
 if __name__ == "__main__":
-    sys.exit(main() or 0)
+    sys.exit(main() or 0)

Modified: team/mjordan/manager-events/build_tools/post_process_documentation.py
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/manager-events/build_tools/post_process_documentation.py?view=diff&rev=368720&r1=368719&r2=368720
==============================================================================
--- team/mjordan/manager-events/build_tools/post_process_documentation.py (original)
+++ team/mjordan/manager-events/build_tools/post_process_documentation.py Mon Jun 11 09:10:30 2012
@@ -15,7 +15,28 @@
 
 from xml.dom.minidom import Element, parse
 
+
 def merge_parameter_information(managerEvent):
+    ''' Merge the parameter information across all managerEventInstances
+    within a managerEvent node '''
+
+    def __swap_parameter_documentation(one, two):
+        # See who has the better documentation and use it
+        if (one.hasChildNodes()):
+            two.parentNode.replaceChild(one.cloneNode(True), two)
+        elif (two.hasChildNodes()):
+            one.parentNode.replaceChild(two.cloneNode(True), one)
+
+    def __merge_parameter(param, other_instances):
+        # Compare the parameter to every other instance's set of parameters
+        for other in other_instances:
+            other_parameters = other.getElementsByTagName("parameter")
+            match = [p for p in other_parameters
+                     if p.getAttribute('name') == param.getAttribute('name')]
+            if (match):
+                # See who has the better documentation and use it
+                __swap_parameter_documentation(param, match[0])
+
     instances = managerEvent.getElementsByTagName("managerEventInstance")
     merged = []
     for instance in instances:
@@ -23,19 +44,9 @@
         parameters = instance.getElementsByTagName("parameter")
         for parameter in parameters:
             if parameter not in merged:
-                # Once we process a parameter, we don't need to do it again for any other
-                # managerEventInstances
                 merged.append(parameter)
-                # Compare the parameter to every other managerEventInstance's set of parameters
-                for other in others:
-                    other_parameters = other.getElementsByTagName("parameter")
-                    match = [p for p in other_parameters if p.getAttribute('name') == parameter.getAttribute('name')]
-                    if (match):
-                        # See who has the better documentation and use it
-                        if (parameter.hasChildNodes()):
-                            match[0].parentNode.replaceChild(parameter.cloneNode(True), match[0])
-                        elif (match[0].hasChildNodes()):
-                            parameter.parentNode.replaceChild(match[0].cloneNode(True), parameter)
+                __merge_parameter(parameter, others)
+
 
 def collapse_event_pair(managerEventOne, managerEventTwo):
     # Move all children of managerEventTwo to managerEventOne
@@ -44,8 +55,8 @@
 
     return managerEventOne
 
+
 def collapse_manager_events(rootNode, managerEvents):
-
     events = {}
     for managerEvent in managerEvents:
         rootNode.removeChild(managerEvent)
@@ -62,16 +73,17 @@
         rootNode.appendChild(event)
     return
 
+
 def main(argv=None):
 
     if argv is None:
         argv = sys.argv
 
     parser = optparse.OptionParser()
-    parser.add_option('-i', '--input', dest = 'input_file',
+    parser.add_option('-i', '--input', dest='input_file',
                       default='doc/core-full-en_US.xml',
                       help='The XML file to process')
-    parser.add_option('-o', '--output', dest = 'output_file',
+    parser.add_option('-o', '--output', dest='output_file',
                       default='doc/core-en_US.xml',
                       help='The XML file to create')
     (options, args) = parser.parse_args(argv)
@@ -90,4 +102,4 @@
     return 0
 
 if __name__ == "__main__":
-    sys.exit(main() or 0)
+    sys.exit(main() or 0)




More information about the asterisk-commits mailing list