Package helium :: Module documentation |
[hide private]
[frames] | no frames]

# Source Code for Module helium.documentation

     1  #============================================================================
     2  #Name        : documentation.py
     3  #Part of     : Helium
     4
     5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     6  #All rights reserved.
     7  #This component and the accompanying materials are made available
     8  #under the terms of the License "Eclipse Public License v1.0"
     9  #which accompanies this distribution, and is available
    10  #at the URL "http://www.eclipse.org/legal/epl-v10.html".
    11  #
    12  #Initial Contributors:
    13  #Nokia Corporation - initial contribution.
    14  #
    15  #Contributors:
    16  #
    17  #Description:
    18  #===============================================================================
    19
    20  """ Helium API documentation processing. """
    21
    22  from lxml import etree
    23
    24
    25 -class APIDeltaWriter(object):
    26      """ Creates an XML delta of the Helium API between releases. """
    27 -    def __init__(self, old_database, new_database):
    28          """ Initialisation. """
    29          self.old_database = old_database
    30          self.new_database = new_database
    31
    32 -    def write(self, path):
    33          """ Write the API delta information to an XML file. """
    34          root = etree.Element('apiChanges')
    35
    36          old_db = etree.parse(self.old_database)
    37          new_db = etree.parse(self.new_database)
    38
    39
    40          old_macro_names = set([macro[0].text for macro in old_db.findall('/project/macro')])
    41          new_macro_names = set([macro[0].text for macro in new_db.findall('/project/macro')])
    42
    43          old_target_names = set([target[0].text for target in old_db.findall('/project/target')])
    44          new_target_names = set([target[0].text for target in new_db.findall('/project/target')])
    45
    46          old_property_names = set([property[0].text for property in old_db.findall('/project/property')])
    47          new_property_names = set([property[0].text for property in new_db.findall('/project/property')])
    48
    49          old_project_names = set([project[0].text for project in old_db.findall('/project')])
    50          new_project_names = set([project[0].text for project in new_db.findall('/project')])
    51
    52          projects_removed = old_project_names.difference(new_project_names)
    53          for project in projects_removed:
    54              project_element = etree.SubElement(root, 'project', attrib={'state': 'removed'})
    55              project_element.text = project
    56          projects_added = new_project_names.difference(old_project_names)
    57          for project in projects_added:
    58              project_element = etree.SubElement(root, 'project', attrib={'state': 'added'})
    59              project_element.text = project
    60
    61          propertys_removed = old_property_names.difference(new_property_names)
    62          for property in propertys_removed:
    63              property_element = etree.SubElement(root, 'property', attrib={'state': 'removed'})
    64              property_element.text = property
    65          propertys_added = new_property_names.difference(old_property_names)
    66          for property in propertys_added:
    67              property_element = etree.SubElement(root, 'property', attrib={'state': 'added'})
    68              property_element.text = property
    69
    70          macros_removed = old_macro_names.difference(new_macro_names)
    71          for macro in macros_removed:
    72              macro_element = etree.SubElement(root, 'macro', attrib={'state': 'removed'})
    73              macro_element.text = macro
    74          macros_added = new_macro_names.difference(old_macro_names)
    75          for macro in macros_added:
    76              macro_element = etree.SubElement(root, 'macro', attrib={'state': 'added'})
    77              macro_element.text = macro
    78          targets_removed = old_target_names.difference(new_target_names)
    79
    80          for target in targets_removed:
    81              target_element = etree.SubElement(root, 'target', attrib={'state': 'removed'})
    82              target_element.text = target
    83          targets_added = new_target_names.difference(old_target_names)
    84          for target in targets_added:
    85              target_element = etree.SubElement(root, 'target', attrib={'state': 'added'})
    86              target_element.text = target
    87
    88          etree.dump(root)
    89          tree = etree.ElementTree(root)
    90          tree.write(path, pretty_print=True)
    91