sbsv2/raptor/bin/sbs_check_exports.py
author William Roberts <williamr@symbian.org>
Thu, 24 Jun 2010 14:23:13 +0100
changeset 598 0a541d1f13c3
parent 37 d806416fc9bf
permissions -rw-r--r--
Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
598
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     1
#!/usr/bin/python
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     2
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     3
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     4
# All rights reserved.
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     5
# This component and the accompanying materials are made available
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     6
# under the terms of the License "Eclipse Public License v1.0"
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     7
# which accompanies this distribution, and is available
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     8
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
     9
#
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    10
# Initial Contributors:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    11
# Nokia Corporation - initial contribution.
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    12
#
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    13
# Contributors:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    14
#
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    15
# Description:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    16
#
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    17
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    18
import re
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    19
import sys
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    20
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    21
# there are no options, so print help if any are passed
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    22
if len(sys.argv) > 1:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    23
	print "usage:", sys.argv[0], "(The log data is read from stdin)"
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    24
	sys.exit(0)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    25
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    26
whatlogRE = re.compile("<whatlog.*bldinf='([^']*)'")
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    27
exportRE = re.compile("<export destination='(.*)' source='(.*)'")
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    28
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    29
bldinf = "unknown"
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    30
sources = {}		# lookup from source to destination
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    31
destinations = {}	# lookup from destination to source
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    32
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    33
chains = 0
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    34
repeats = 0
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    35
conflicts = []
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    36
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    37
# read stdin a line at a time and soak up all the exports
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    38
line = " "
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    39
while line:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    40
	line = sys.stdin.readline()
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    41
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    42
	whatlogMatch = whatlogRE.search(line)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    43
	if whatlogMatch:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    44
		bldinf = whatlogMatch.group(1).lower()
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    45
		continue
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    46
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    47
	exportMatch = exportRE.search(line)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    48
	if exportMatch:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    49
		destination = exportMatch.group(1).lower()
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    50
		source = exportMatch.group(2).lower()
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    51
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    52
		if destination in destinations:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    53
			(otherSource, otherBldinf) = destinations[destination]
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    54
			
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    55
			# same source and destination but different bld.inf => repeat	
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    56
			if source == otherSource and bldinf != otherBldinf:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    57
				# only interested in the number for now
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    58
				repeats += 1
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    59
				
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    60
			# different source but same destination => conflict
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    61
			if source != otherSource:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    62
				conflict = (source, destination, bldinf, otherSource, otherBldinf)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    63
				tcilfnoc = (otherSource, destination, otherBldinf, source, bldinf)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    64
				
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    65
				if conflict in conflicts or tcilfnoc in conflicts:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    66
					# seen this conflict before
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    67
					pass
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    68
				else:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    69
					print "CONFLICT:", destination, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    70
						"FROM", source, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    71
						"IN", bldinf, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    72
						"AND FROM", otherSource, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    73
						"IN", otherBldinf
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    74
					conflicts.append(conflict)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    75
		else:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    76
			sources[source] = [destination, bldinf]
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    77
			destinations[destination] = [source, bldinf]
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    78
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    79
# now check for destinations which were also sources => chains
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    80
for destination in destinations:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    81
	if destination in sources:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    82
		(nextDestination, inf2) = sources[destination]
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    83
		(source, inf1) = destinations[destination]
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    84
		print "CHAIN:", source, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    85
			"TO", destination, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    86
			"IN", inf1, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    87
			"THEN TO", nextDestination, \
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    88
			"IN", inf2
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    89
		chains += 1
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    90
		
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    91
# print a summary
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    92
print "Total exports = ", len(destinations.keys())
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    93
print "Chained exports = ", chains
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    94
print "Repeated exports = ", repeats
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    95
print "Conflicting exports = ", len(conflicts)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    96
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    97
# return the error code
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    98
if conflicts:
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
    99
	sys.exit(1)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
   100
sys.exit(0)
0a541d1f13c3 Clean up licenses and remove .bak files (cf changes 56dd7656a965 and 238f4cb8391f)
William Roberts <williamr@symbian.org>
parents: 37
diff changeset
   101