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