buildframework/helium/sf/python/pythoncore/lib/helium/documentation.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 587 85df38eb4012
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : documentation.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
""" Helium API documentation processing. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    22
import amara
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
class APIDeltaWriter(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
    """ Creates an XML delta of the Helium API between releases. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
    def __init__(self, old_database, new_database):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
        self.old_database = old_database
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
        self.new_database = new_database
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
    def write(self, path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
        """ Write the API delta information to an XML file. """
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    33
        root = amara.create_document('apiChanges')
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    35
        old_db = amara.parse(self.old_database)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    36
        new_db = amara.parse(self.new_database)        
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    38
        old_macro_names = set([str(macro.name) for macro in old_db.xml_xpath('/antDatabase/project/macro')])
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    39
        new_macro_names = set([str(macro.name) for macro in new_db.xml_xpath('/antDatabase/project/macro')])
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    41
        old_target_names = set([str(target.name) for target in old_db.xml_xpath('/antDatabase/project/target')])
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    42
        new_target_names = set([str(target.name) for target in new_db.xml_xpath('/antDatabase/project/target')])
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    43
        new_target_names_public = set([str(target.name) for target in new_db.xml_xpath("/antDatabase/project/target[scope='public']")])
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    45
        old_property_names = set([str(property_.name) for property_ in old_db.xml_xpath('/antDatabase/project/property')])
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    46
        new_property_names = set([str(property_.name) for property_ in new_db.xml_xpath('/antDatabase/project/property')])
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    47
        new_property_names_public = set([str(property_.name) for property_ in new_db.xml_xpath("/antDatabase/project/property[scope='public']")])
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    49
        old_project_names = set([str(project.name) for project in old_db.xml_xpath('/antDatabase/project')])
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    50
        new_project_names = set([str(project.name) for project in new_db.xml_xpath('/antDatabase/project')])
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        dict_old_taskdef_names  = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        dict_new_taskdef_names  = {}
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    54
        for taskdef in old_db.xml_xpath('/antDatabase/project/taskdef'):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    55
            dict_old_taskdef_names[taskdef.name] = taskdef.name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    56
        for taskdef in new_db.xml_xpath('/antDatabase/project/taskdef'):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    57
            dict_new_taskdef_names[taskdef.name] = taskdef.name
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        projects_removed = old_project_names.difference(new_project_names)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        for project in projects_removed:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    61
            root.xml_append(root.xml_create_element('project', attributes={'state': 'removed'}, content=project))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        projects_added = new_project_names.difference(old_project_names)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        for project in projects_added:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    64
            root.xml_append(root.xml_create_element('project', attributes={'state': 'added'}, content=project))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        propertys_removed = old_property_names.difference(new_property_names)
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    67
        for property_ in propertys_removed:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    68
            root.xml_append(root.xml_create_element('property', attributes={'state': 'removed'}, content=property_))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        propertys_added = new_property_names.difference(old_property_names)
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    70
        for property_ in propertys_added:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    71
            if property_ in new_property_names_public or new_property_names_public == set([]):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    72
                root.xml_append(root.xml_create_element('property', attributes={'state': 'added'}, content=property_))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        macros_removed = old_macro_names.difference(new_macro_names)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        for macro in macros_removed:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    76
            root.xml_append(root.xml_create_element('macro', attributes={'state': 'removed'}, content=macro))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        macros_added = new_macro_names.difference(old_macro_names)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        for macro in macros_added:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    79
            root.xml_append(root.xml_create_element('macro', attributes={'state': 'added'}, content=macro))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        targets_removed = old_target_names.difference(new_target_names)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        for target in targets_removed:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    83
            root.xml_append(root.xml_create_element('target', attributes={'state': 'removed'}, content=target))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        targets_added = new_target_names.difference(old_target_names)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        for target in targets_added:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    86
            if target in new_target_names_public or new_target_names_public == set([]):
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    87
                root.xml_append(root.xml_create_element('target', attributes={'state': 'added'}, content=target))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        taskdefs_removed = set(dict_old_taskdef_names.keys()) - set(dict_new_taskdef_names.keys()) 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        for taskdefKey in taskdefs_removed:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    91
            taskdef_element = root.xml_create_element('taskdef', attributes={'state': 'removed'}, content=str(taskdefKey))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    92
            root.xml_append(taskdef_element)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    93
            taskdef_element.classname = dict_old_taskdef_names[taskdefKey]
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        taskdefs_added = set(dict_new_taskdef_names.keys()) - set(dict_old_taskdef_names.keys())
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        for taskdefKey in taskdefs_added:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    96
            taskdef_element = root.xml_create_element('taskdef', attributes={'state': 'added'}, content=str(taskdefKey))
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    97
            root.xml_append(taskdef_element)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    98
            taskdef_element.classname = dict_new_taskdef_names[taskdefKey]
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
            
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   100
        f = open(path, 'w')
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   101
        root.xml(indent=True, out=f)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
   102
        f.close()
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106