sbsv2/raptor/python/raptor_xml.py
author timothy.murphy@nokia.com
Tue, 13 Apr 2010 13:26:25 +0100
branchfix
changeset 480 6dc1dae496c0
parent 333 0fe3c56ad89c
child 491 f60c4282816c
permissions -rw-r--r--
Merge fix to RC4 default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     1
#
333
0fe3c56ad89c release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents: 332
diff changeset
     2
# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     3
# All rights reserved.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     4
# This component and the accompanying materials are made available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     6
# which accompanies this distribution, and is available
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     8
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
     9
# Initial Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    10
# Nokia Corporation - initial contribution.
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    11
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    12
# Contributors:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    13
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    14
# Description: 
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    15
# raptor_xml module
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    16
#
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    17
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    18
import os
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    19
import raptor_data
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    20
import raptor_utilities
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    21
import xml.dom.minidom
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    22
import re
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    23
import generic_path
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    24
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    25
# raptor_xml module attributes
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    26
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    27
namespace = "http://symbian.com/xml/build"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    28
xsdVersion = "build/2_0.xsd"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    29
xsdIgnore = "build/666.xsd"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    30
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    31
_constructors = {"alias":raptor_data.Alias,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    32
				 "aliasRef":raptor_data.AliasRef,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    33
				 "append":raptor_data.Append,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    34
				 "env":raptor_data.Env,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    35
				 "group":raptor_data.Group,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    36
				 "groupRef":raptor_data.GroupRef,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    37
				 "interface":raptor_data.Interface,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    38
				 "interfaceRef":raptor_data.InterfaceRef,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    39
				 "param":raptor_data.Parameter,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    40
				 "paramgroup":raptor_data.ParameterGroup,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    41
				 "prepend":raptor_data.Prepend,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    42
				 "set":raptor_data.Set,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    43
				 "spec":raptor_data.Specification,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    44
				 "var":raptor_data.Variant,
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    45
				 "varRef":raptor_data.VariantRef}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    46
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    47
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    48
# raptor_xml module classes
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    49
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    50
class XMLError(Exception):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    51
	pass
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    52
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    53
# raptor_xml module functions
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    54
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    55
def Read(Raptor, filename):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    56
	"Read in a Raptor XML document"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    57
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    58
	# try to read and parse the XML file
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    59
	try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    60
		dom = xml.dom.minidom.parse(filename)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    61
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    62
	except: # a whole bag of exceptions can be raised here
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    63
		raise XMLError
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    64
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    65
	# <build> is always the root element
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    66
	build = dom.documentElement
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    67
	objects = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    68
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    69
	fileVersion = build.getAttribute("xsi:schemaLocation")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    70
	
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    71
	# ignore the file it matches the "invalid" schema
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    72
	if fileVersion.endswith(xsdIgnore):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    73
		return objects
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    74
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    75
	# check that the file matches the expected schema
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    76
	if not fileVersion.endswith(xsdVersion):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    77
		Raptor.Warn("file '%s' uses schema '%s' which does not end with the expected version '%s'", filename, fileVersion, xsdVersion)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    78
		
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    79
	# create a Data Model object from each sub-element
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    80
	for child in build.childNodes:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    81
		if child.namespaceURI == namespace \
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    82
		and child.nodeType == child.ELEMENT_NODE:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    83
			try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    84
				o = XMLtoDataModel(Raptor, child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    85
				if o is not None:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    86
					objects.append(o)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    87
			except raptor_data.InvalidChildError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    88
				Raptor.Warn("Invalid element %s in %s", child.localName, filename)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    89
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    90
	# discard the XML
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    91
	dom.unlink()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    92
	return objects
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    93
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    94
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    95
def XMLtoDataModel(Raptor, node):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    96
	"Create a data-model object from an XML element"
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    97
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    98
	# look-up a function to create an object from the node name
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
    99
	try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   100
		constructor = _constructors[node.localName]
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   101
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   102
	except KeyError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   103
		Raptor.Warn("Unknown element %s", node.localName)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   104
		return
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   105
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   106
	model = constructor()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   107
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   108
	# deal with the attributes first
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   109
	if node.hasAttributes():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   110
		for i in range(node.attributes.length):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   111
			attribute = node.attributes.item(i)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   112
			try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   113
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   114
				model.SetProperty(attribute.localName, attribute.value)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   115
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   116
			except raptor_data.InvalidPropertyError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   117
				Raptor.Warn("Can't set attribute %s for element %s",
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   118
							 attribute.localName, node.localName)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   119
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   120
	# add the sub-elements
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   121
	for child in node.childNodes:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   122
		if child.namespaceURI == namespace \
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   123
		and child.nodeType == child.ELEMENT_NODE:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   124
			try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   125
				gc = XMLtoDataModel(Raptor, child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   126
				if gc is not None:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   127
					model.AddChild(gc)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   128
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   129
			except raptor_data.InvalidChildError:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   130
				Raptor.Warn("Can't add child %s to element %s",
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   131
							 child.localName, node.localName)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   132
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   133
	# only return a valid object (or raise error)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   134
	if model.Valid():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   135
		if model.IsApplicable():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   136
			return model
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   137
		else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   138
			return None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   139
	else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   140
		raise raptor_data.InvalidChildError
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   141
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   142
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   143
class SystemModelComponent(generic_path.Path):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   144
	"""Path sub-class that wraps up a component bld.inf file with
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   145
	system_definition.xml context information."""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   146
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   147
	def __init__(self, aBldInfFile, aLayerName, aContainerNames, aSystemDefinitionFile, aSystemDefinitionBase, aSystemDefinitionVersion):
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   148
		generic_path.Path.__init__(self, aBldInfFile.Absolute().path)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   149
		self.__ContainerNames = aContainerNames
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   150
		self.__LayerName = aLayerName
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   151
		self.__SystemDefinitionFile = aSystemDefinitionFile
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   152
		self.__SystemDefinitionBase = aSystemDefinitionBase
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   153
		self.__SystemDefinitionVersion = aSystemDefinitionVersion
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   154
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   155
	def GetSystemDefinitionFile(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   156
		return self.__SystemDefinitionFile
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   157
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   158
	def GetSystemDefinitionBase(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   159
		return self.__SystemDefinitionBase
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   160
333
0fe3c56ad89c release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents: 332
diff changeset
   161
	def GetSystemDefinitionVersion(self):
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   162
		return self.__SystemDefinitionVersion
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   163
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   164
	def GetLayerName(self):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   165
		return self.__LayerName
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   166
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   167
	def GetContainerName(self, aContainerType):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   168
		if self.__ContainerNames.has_key(aContainerType):
333
0fe3c56ad89c release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents: 332
diff changeset
   169
			return self.__ContainerNames[aContainerType]
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   170
		return ""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   171
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   172
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   173
class SystemModel(object):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   174
	"""A representation of the SystemModel section of a Symbian system_definition.xml file."""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   175
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   176
	def __init__(self, aLogger, aSystemDefinitionFile, aSystemDefinitionBase):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   177
		self.__Logger = aLogger
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   178
		self.__SystemDefinitionFile = aSystemDefinitionFile.GetLocalString()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   179
		self.__SystemDefinitionBase = aSystemDefinitionBase.GetLocalString()
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   180
		self.__Version = {'MAJOR':0,'MID':0,'MINOR':0}
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   181
		self.__IdAttribute = "name"
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   182
		self.__ComponentRoot = ""
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   183
		self.__TotalComponents = 0
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   184
		self.__LayerList = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   185
		self.__LayerDetails = {}
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   186
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   187
		self.__DOM = None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   188
		self.__SystemDefinitionElement = None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   189
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   190
		if self.__Read():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   191
			if self.__Validate():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   192
				self.__Parse()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   193
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   194
		if self.__DOM:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   195
			self.__DOM.unlink()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   196
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   197
	def HasLayer(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   198
		return aLayer in self.__LayerList
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   199
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   200
	def GetLayerNames(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   201
		return self.__LayerList
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   202
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   203
	def GetLayerComponents(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   204
		if not self.HasLayer(aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   205
			self.__Logger.Error("System Definition layer \"%s\" does not exist in %s", aLayer, self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   206
			return []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   207
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   208
		return self.__LayerDetails[aLayer]
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   209
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   210
	def IsLayerBuildable(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   211
		if len(self.GetLayerComponents(aLayer)):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   212
			return True
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   213
		return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   214
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   215
	def GetAllComponents(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   216
		components = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   217
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   218
		for layer in self.GetLayerNames():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   219
			components.extend(self.GetLayerComponents(layer))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   220
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   221
		return components
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   222
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   223
	def DumpLayerInfo(self, aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   224
		if self.HasLayer(aLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   225
			self.__Logger.Info("Found %d bld.inf references in layer \"%s\"", len(self.GetLayerComponents(aLayer)), aLayer)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   226
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   227
	def DumpInfo(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   228
		self.__Logger.Info("Found %d bld.inf references in %s within %d layers:", len(self.GetAllComponents()), self.__SystemDefinitionFile, len(self.GetLayerNames()))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   229
		self.__Logger.Info("\t%s", ", ".join(self.GetLayerNames()))
29
ee00c00df073 Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents: 3
diff changeset
   230
		self.__Logger.InfoDiscovery(object_type = "layers",
ee00c00df073 Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents: 3
diff changeset
   231
				count = len(self.GetLayerNames()))
ee00c00df073 Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents: 3
diff changeset
   232
		self.__Logger.InfoDiscovery(object_type = "bld.inf references",
ee00c00df073 Catchup to Perforce WIP with timing, python24
timothy.murphy@nokia.com
parents: 3
diff changeset
   233
				count = len(self.GetAllComponents()))
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   234
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   235
	def __Read(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   236
		if not os.path.exists(self.__SystemDefinitionFile):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   237
			self.__Logger.Error("System Definition file %s does not exist", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   238
			return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   239
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   240
		self.__Logger.Info("System Definition file %s", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   241
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   242
		# try to read the XML file
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   243
		try:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   244
			self.__DOM = xml.dom.minidom.parse(self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   245
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   246
		except: # a whole bag of exceptions can be raised here
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   247
			self.__Logger.Error("Failed to parse XML file %s", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   248
			return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   249
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   250
		# <SystemDefinition> is always the root element
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   251
		self.__SystemDefinitionElement = self.__DOM.documentElement
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   252
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   253
		return True
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   254
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   255
	def __Validate(self):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   256
		# account for different schema versions in processing
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   257
		# old format : version >= 1.3.0
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   258
		# new format : version >= 2.0.0 (assume later versions are compatible...at least for now)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   259
		version = re.match(r'(?P<MAJOR>\d)\.(?P<MID>\d)(\.(?P<MINOR>\d))?', self.__SystemDefinitionElement.getAttribute("schema"))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   260
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   261
		if not version:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   262
			self.__Logger.Error("Cannot determine schema version of XML file %s", self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   263
			return False
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   264
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   265
		self.__Version['MAJOR'] = int(version.group('MAJOR'))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   266
		self.__Version['MID'] = int(version.group('MID'))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   267
		self.__Version['MINOR'] = int(version.group('MINOR'))
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   268
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   269
		if self.__Version['MAJOR'] == 1 and self.__Version['MID'] > 2:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   270
			self.__ComponentRoot = self.__SystemDefinitionBase
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   271
		elif self.__Version['MAJOR'] == 2 or self.__Version['MAJOR'] == 3:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   272
			# 2.0.x and 3.0.0 formats support SOURCEROOT or SRCROOT as an environment specified base - we respect this, unless
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   273
			# explicitly overridden on the command line
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   274
			if os.environ.has_key('SRCROOT'):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   275
				self.__ComponentRoot = generic_path.Path(os.environ['SRCROOT'])
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   276
			elif os.environ.has_key('SOURCEROOT'):
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   277
				self.__ComponentRoot = generic_path.Path(os.environ['SOURCEROOT'])
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   278
				
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   279
			if self.__SystemDefinitionBase and self.__SystemDefinitionBase != ".":
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   280
				self.__ComponentRoot = self.__SystemDefinitionBase
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   281
				if os.environ.has_key('SRCROOT'):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   282
					self.__Logger.Info("Command line specified System Definition file base \'%s\' overriding environment SRCROOT \'%s\'", self.__SystemDefinitionBase, os.environ['SRCROOT'])
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   283
				elif os.environ.has_key('SOURCEROOT'):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   284
					self.__Logger.Info("Command line specified System Definition file base \'%s\' overriding environment SOURCEROOT \'%s\'", self.__SystemDefinitionBase, os.environ['SOURCEROOT'])
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   285
		else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   286
			self.__Logger.Error("Cannot process schema version %s of file %s", version.string, self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   287
			return False
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   288
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   289
		if self.__Version['MAJOR'] >= 3:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   290
			# id is the unique identifier for 3.0 and later schema
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   291
			self.__IdAttribute = "id"
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   292
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   293
		return True
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   294
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   295
	def __Parse(self):
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   296
		# For 2.0 and earlier: find the <systemModel> element (there can be 0 or 1) and search any <layer> elements for <unit> elements with "bldFile" attributes
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   297
		# the <layer> context of captured "bldFile" attributes is recorded as we go
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   298
		# For 3.0 and later, process any architectural topmost element, use the topmost element with an id as the "layer"
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   299
		for child in self.__SystemDefinitionElement.childNodes:
333
0fe3c56ad89c release note: prototype System Definition v3 support
Richard Taylor <richard.i.taylor@nokia.com>
parents: 332
diff changeset
   300
			if child.localName in ["systemModel", "layer", "package", "collection", "component"]:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   301
				self.__ProcessSystemModelElement(child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   302
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   303
	def __CreateComponent(self, aBldInfFile, aUnitElement):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   304
		# take a resolved bld.inf file and associated <unit/> element and returns a populated Component object
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   305
		containers = {}
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   306
		self.__GetElementContainers(aUnitElement, containers)
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   307
		layer = self.__GetEffectiveLayer(aUnitElement)
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   308
		component = SystemModelComponent(aBldInfFile, layer, containers, self.__SystemDefinitionFile, self.__SystemDefinitionBase, self.__Version)
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   309
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   310
		return component
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   311
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   312
	def __GetEffectiveLayer(self, aElement):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   313
		#' return the ID of the topmost item which has an ID. For 1.x and 2.x, this will always be layer, for 3.x, it will be the topmost ID'd element in the file
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   314
		# never call this on the root element
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   315
		if aElement.parentNode.hasAttribute(self.__IdAttribute):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   316
			return self.__GetEffectiveLayer(aElement.parentNode)
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   317
		elif aElement.hasAttribute(self.__IdAttribute):
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   318
			return aElement.getAttribute(self.__IdAttribute)
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   319
		return ""
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   320
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   321
	def __GetElementContainers(self, aElement, aContainers):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   322
		# take a <unit/> element and creates a type->name dictionary of all of its parent containers
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   323
		# We're only interested in parent nodes if they're not the top-most node
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   324
		if aElement.parentNode.parentNode:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   325
			parent = aElement.parentNode
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   326
			name = parent.getAttribute(self.__IdAttribute)
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   327
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   328
			if name:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   329
				aContainers[parent.tagName] = name
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   330
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   331
			self.__GetElementContainers(parent, aContainers)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   332
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   333
	def __ProcessSystemModelElement(self, aElement):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   334
		"""Search for XML <unit/> elements with 'bldFile' attributes and resolve concrete bld.inf locations
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   335
		with an appreciation of different schema versions."""
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   336
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   337
		# The effective "layer" is the item whose parent does not have an id (or name in 2.x and earlier)
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   338
		if not aElement.parentNode.hasAttribute(self.__IdAttribute) :
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   339
			currentLayer = aElement.getAttribute(self.__IdAttribute)
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   340
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   341
			if not self.__LayerDetails.has_key(currentLayer):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   342
				self.__LayerDetails[currentLayer] = []
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   343
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   344
			if not currentLayer in self.__LayerList:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   345
				self.__LayerList.append(currentLayer)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   346
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   347
		elif aElement.tagName == "unit" and aElement.hasAttributes():
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   348
			bldFileValue = aElement.getAttribute("bldFile")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   349
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   350
			if bldFileValue:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   351
				bldInfRoot = self.__ComponentRoot
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   352
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   353
				if self.__Version['MAJOR'] == 1:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   354
					# version 1.x schema paths can use DOS slashes
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   355
					bldFileValue = raptor_utilities.convertToUnixSlash(bldFileValue)
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   356
				elif self.__Version['MAJOR'] >= 2:
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   357
					# version 2.x.x schema paths are subject to a "root" attribute off-set, if it exists
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   358
					rootValue = aElement.getAttribute("root")
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   359
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   360
					if rootValue:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   361
						if os.environ.has_key(rootValue):
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   362
							bldInfRoot = generic_path.Path(os.environ[rootValue])
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   363
						else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   364
							# Assume that this is an error i.e. don't attempt to resolve in relation to SOURCEROOT
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   365
							bldInfRoot = None
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   366
							self.__Logger.Error("Cannot resolve \'root\' attribute value \"%s\" in %s", rootValue, self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   367
							return
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   368
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   369
				group = generic_path.Path(bldFileValue)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   370
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   371
				if self.__Version['MAJOR'] < 3:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   372
					# absolute paths are not changed by root var in 1.x and 2.x
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   373
					if not group.isAbsolute() and bldInfRoot:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   374
						group = generic_path.Join(bldInfRoot, group)
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   375
				else:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   376
					# only absolute paths are changed by root var in 3.x
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   377
					if group.isAbsolute() and bldInfRoot:
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   378
						group = generic_path.Join(bldInfRoot, group)
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   379
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   380
				bldinf = generic_path.Join(group, "bld.inf").FindCaseless()
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   381
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   382
				if bldinf == None:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   383
					self.__Logger.Error("No bld.inf found at %s in %s", group.GetLocalString(), self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   384
				else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   385
					component = self.__CreateComponent(bldinf, aElement)
332
dae2dfe18db2 prototype of sysdef v3.0 parser
Richard Taylor <richard.i.taylor@nokia.com>
parents: 29
diff changeset
   386
					layer = component.GetLayerName()
3
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   387
					if layer:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   388
						self.__LayerDetails[layer].append(component)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   389
						self.__TotalComponents += 1
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   390
					else:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   391
						self.__Logger.Error("No containing layer found for %s in %s", str(bldinf), self.__SystemDefinitionFile)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   392
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   393
		# search the sub-elements
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   394
		for child in aElement.childNodes:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   395
			if child.nodeType == child.ELEMENT_NODE:
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   396
				self.__ProcessSystemModelElement(child)
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   397
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   398
e1eecf4d390d Team sf branch.
tnmurphy@4GBL06592.nokia.com
parents: 0
diff changeset
   399
# end of the raptor_xml module