587
|
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 |
|
628
|
22 |
import amara
|
587
|
23 |
|
|
24 |
class APIDeltaWriter(object):
|
|
25 |
""" Creates an XML delta of the Helium API between releases. """
|
|
26 |
def __init__(self, old_database, new_database):
|
|
27 |
""" Initialisation. """
|
|
28 |
self.old_database = old_database
|
|
29 |
self.new_database = new_database
|
|
30 |
|
|
31 |
def write(self, path):
|
|
32 |
""" Write the API delta information to an XML file. """
|
628
|
33 |
root = amara.create_document('apiChanges')
|
587
|
34 |
|
628
|
35 |
old_db = amara.parse(self.old_database)
|
|
36 |
new_db = amara.parse(self.new_database)
|
587
|
37 |
|
628
|
38 |
old_macro_names = set([str(macro.name) for macro in old_db.xml_xpath('/antDatabase/project/macro')])
|
|
39 |
new_macro_names = set([str(macro.name) for macro in new_db.xml_xpath('/antDatabase/project/macro')])
|
587
|
40 |
|
628
|
41 |
old_target_names = set([str(target.name) for target in old_db.xml_xpath('/antDatabase/project/target')])
|
|
42 |
new_target_names = set([str(target.name) for target in new_db.xml_xpath('/antDatabase/project/target')])
|
|
43 |
new_target_names_public = set([str(target.name) for target in new_db.xml_xpath("/antDatabase/project/target[scope='public']")])
|
587
|
44 |
|
628
|
45 |
old_property_names = set([str(property_.name) for property_ in old_db.xml_xpath('/antDatabase/project/property')])
|
|
46 |
new_property_names = set([str(property_.name) for property_ in new_db.xml_xpath('/antDatabase/project/property')])
|
|
47 |
new_property_names_public = set([str(property_.name) for property_ in new_db.xml_xpath("/antDatabase/project/property[scope='public']")])
|
587
|
48 |
|
628
|
49 |
old_project_names = set([str(project.name) for project in old_db.xml_xpath('/antDatabase/project')])
|
|
50 |
new_project_names = set([str(project.name) for project in new_db.xml_xpath('/antDatabase/project')])
|
587
|
51 |
|
|
52 |
dict_old_taskdef_names = {}
|
|
53 |
dict_new_taskdef_names = {}
|
628
|
54 |
for taskdef in old_db.xml_xpath('/antDatabase/project/taskdef'):
|
|
55 |
dict_old_taskdef_names[taskdef.name] = taskdef.name
|
|
56 |
for taskdef in new_db.xml_xpath('/antDatabase/project/taskdef'):
|
|
57 |
dict_new_taskdef_names[taskdef.name] = taskdef.name
|
587
|
58 |
|
|
59 |
projects_removed = old_project_names.difference(new_project_names)
|
|
60 |
for project in projects_removed:
|
628
|
61 |
root.xml_append(root.xml_create_element('project', attributes={'state': 'removed'}, content=project))
|
587
|
62 |
projects_added = new_project_names.difference(old_project_names)
|
|
63 |
for project in projects_added:
|
628
|
64 |
root.xml_append(root.xml_create_element('project', attributes={'state': 'added'}, content=project))
|
587
|
65 |
|
|
66 |
propertys_removed = old_property_names.difference(new_property_names)
|
628
|
67 |
for property_ in propertys_removed:
|
|
68 |
root.xml_append(root.xml_create_element('property', attributes={'state': 'removed'}, content=property_))
|
587
|
69 |
propertys_added = new_property_names.difference(old_property_names)
|
628
|
70 |
for property_ in propertys_added:
|
|
71 |
if property_ in new_property_names_public or new_property_names_public == set([]):
|
|
72 |
root.xml_append(root.xml_create_element('property', attributes={'state': 'added'}, content=property_))
|
587
|
73 |
|
|
74 |
macros_removed = old_macro_names.difference(new_macro_names)
|
|
75 |
for macro in macros_removed:
|
628
|
76 |
root.xml_append(root.xml_create_element('macro', attributes={'state': 'removed'}, content=macro))
|
587
|
77 |
macros_added = new_macro_names.difference(old_macro_names)
|
|
78 |
for macro in macros_added:
|
628
|
79 |
root.xml_append(root.xml_create_element('macro', attributes={'state': 'added'}, content=macro))
|
587
|
80 |
targets_removed = old_target_names.difference(new_target_names)
|
|
81 |
|
|
82 |
for target in targets_removed:
|
628
|
83 |
root.xml_append(root.xml_create_element('target', attributes={'state': 'removed'}, content=target))
|
587
|
84 |
targets_added = new_target_names.difference(old_target_names)
|
|
85 |
for target in targets_added:
|
628
|
86 |
if target in new_target_names_public or new_target_names_public == set([]):
|
|
87 |
root.xml_append(root.xml_create_element('target', attributes={'state': 'added'}, content=target))
|
587
|
88 |
|
|
89 |
taskdefs_removed = set(dict_old_taskdef_names.keys()) - set(dict_new_taskdef_names.keys())
|
|
90 |
for taskdefKey in taskdefs_removed:
|
628
|
91 |
taskdef_element = root.xml_create_element('taskdef', attributes={'state': 'removed'}, content=str(taskdefKey))
|
|
92 |
root.xml_append(taskdef_element)
|
|
93 |
taskdef_element.classname = dict_old_taskdef_names[taskdefKey]
|
587
|
94 |
taskdefs_added = set(dict_new_taskdef_names.keys()) - set(dict_old_taskdef_names.keys())
|
|
95 |
for taskdefKey in taskdefs_added:
|
628
|
96 |
taskdef_element = root.xml_create_element('taskdef', attributes={'state': 'added'}, content=str(taskdefKey))
|
|
97 |
root.xml_append(taskdef_element)
|
|
98 |
taskdef_element.classname = dict_new_taskdef_names[taskdefKey]
|
587
|
99 |
|
628
|
100 |
f = open(path, 'w')
|
|
101 |
root.xml(indent=True, out=f)
|
|
102 |
f.close()
|
587
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|