author | MattD <mattd@symbian.org> |
Thu, 11 Mar 2010 13:23:18 +0000 | |
changeset 923 | 5ccf9d5ab663 |
parent 753 | 5069de517698 |
permissions | -rw-r--r-- |
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
1 |
#!perl -w |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
2 |
# |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
3 |
# Copyright (c) 2009 Symbian Foundation Ltd |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
8 |
# |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
9 |
# Initial Contributors: |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
10 |
# Symbian Foundation Ltd - initial contribution. |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
11 |
# |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
12 |
# Contributors: |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
13 |
# |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
14 |
# Description: |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
15 |
# Identifies failures in a log file (as determined by a set of rules) and produces a BRAG XML summary |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
16 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
17 |
use strict; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
18 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
19 |
use Getopt::Long; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
20 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
21 |
my $phaseName; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
22 |
my $stepName; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
23 |
my $rulesFile; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
24 |
my $help = 0; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
25 |
GetOptions(( |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
26 |
'phase=s' => \$phaseName, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
27 |
'step=s' => \$stepName, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
28 |
'rules=s' => \$rulesFile, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
29 |
'help!' => \$help, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
30 |
)); |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
31 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
32 |
my $wrongArgs = 0; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
33 |
unless ($help) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
34 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
35 |
$wrongArgs += warn "No phase specified to indicate the phase that the failures fall under\n" unless defined $phaseName; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
36 |
$wrongArgs += warn "No step specified to indicate the step that the failures fall under\n" unless defined $stepName; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
37 |
$wrongArgs += warn "No file of rules specified to interpret the log file\n" unless defined $rulesFile; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
38 |
$wrongArgs += warn "No log files to process\n" unless @ARGV; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
39 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
40 |
if ($help || $wrongArgs) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
41 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
42 |
print <<"EOT"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
43 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
44 |
logToBRAG.pl --phase=prebuild --step=syncsource --rules=syncsourceRules.tsv presync.log [doSync.log ...] > output.xml |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
45 |
EOT |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
46 |
exit(0 + !$help); |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
47 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
48 |
|
579
78b42fd9e2c4
Added code to handle the script being given a log file argument which includes wild cards.
Simon Howkins <simonh@symbian.org>
parents:
578
diff
changeset
|
49 |
# Do the wild-carding thing |
78b42fd9e2c4
Added code to handle the script being given a log file argument which includes wild cards.
Simon Howkins <simonh@symbian.org>
parents:
578
diff
changeset
|
50 |
@ARGV = map { glob $_ } @ARGV; |
78b42fd9e2c4
Added code to handle the script being given a log file argument which includes wild cards.
Simon Howkins <simonh@symbian.org>
parents:
578
diff
changeset
|
51 |
|
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
52 |
# Start to build structure to be output as XML (same format as XML::Parser would create for us) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
53 |
my $xmlNewline = bless { Text => "\n" }, "Characters"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
54 |
my $step = bless { |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
55 |
name => $stepName, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
56 |
Kids => [ $xmlNewline ] |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
57 |
}, "step"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
58 |
my $phase = bless { |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
59 |
name => $phaseName, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
60 |
Kids => [ $xmlNewline, $step, $xmlNewline ] |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
61 |
}, "phase"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
62 |
my $buildStatus = [ bless { |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
63 |
Kids => |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
64 |
[ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
65 |
$xmlNewline, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
66 |
$phase, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
67 |
$xmlNewline, |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
68 |
] |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
69 |
}, "buildStatus"]; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
70 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
71 |
# Also create empty <failures> tags with severities in a sensible order |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
72 |
# And shortcuts to those items |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
73 |
my $severityShortcut = {}; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
74 |
foreach my $severity (qw{critical major minor}) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
75 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
76 |
my $failureSet = bless { level => $severity, Kids => [ $xmlNewline ] }, "failures"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
77 |
push @{$step->{Kids}}, $failureSet, $xmlNewline; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
78 |
$severityShortcut->{$severity} = $failureSet; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
79 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
80 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
81 |
# Read rules file |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
82 |
my @rules; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
83 |
open(TSV, $rulesFile) or die "Unable to open rules file '$rulesFile'\n"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
84 |
while (my $line = <TSV>) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
85 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
86 |
chomp $line; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
87 |
next unless $line; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
88 |
my @terms = split m{\t+}, $line; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
89 |
die "Rules file not formatted as expected at line $.\n" unless scalar @terms == 2; |
578
75fa4158340a
Fixed handling or regular expression strings, so the regular expression functiuonality works, not just substring detection!
Simon Howkins <simonh@symbian.org>
parents:
576
diff
changeset
|
90 |
push @rules, { regexp => qr{$terms[0]}, severity => $terms[1] }; |
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
91 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
92 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
93 |
# Iterate through all the lines of all the files in @ARGV |
576
7be9799d1a41
Pre-emptive performance fix - avoid having to read the complete log file into memory at the same time before processing it.
Simon Howkins <simonh@symbian.org>
parents:
572
diff
changeset
|
94 |
while (my $line = <>) |
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
95 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
96 |
chomp $line; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
97 |
foreach my $rule (@rules) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
98 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
99 |
if ($line =~ m[$rule->{regexp}]) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
100 |
{ |
578
75fa4158340a
Fixed handling or regular expression strings, so the regular expression functiuonality works, not just substring detection!
Simon Howkins <simonh@symbian.org>
parents:
576
diff
changeset
|
101 |
last if $rule->{severity} eq "ignore"; |
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
102 |
# We found a match |
753
5069de517698
New script which parses raptor logs directly to produce a BRAG summary.
Simon Howkins <simonh@symbian.org>
parents:
580
diff
changeset
|
103 |
my $failure = bless{ Kids => [ bless { Kids => [ bless { Text => $line }, "Characters" ]}, "effect"] }, "failure"; |
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
104 |
# Ensure we have a <failures> tag for this severity |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
105 |
if (!exists $severityShortcut->{$rule->{severity}}) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
106 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
107 |
# Create the failure set and add it to the shortcut list too |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
108 |
my $failureSet = bless { level => $rule->{severity}, Kids => [ $xmlNewline ] }, "failures"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
109 |
push @{$step->{Kids}}, $failureSet, $xmlNewline; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
110 |
$severityShortcut->{$rule->{severity}} = $failureSet; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
111 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
112 |
push @{$severityShortcut->{$rule->{severity}}->{Kids}}, $failure, $xmlNewline; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
113 |
# Do not consider any more rules |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
114 |
last; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
115 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
116 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
117 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
118 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
119 |
# Print XML |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
120 |
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
121 |
print "<?xml-stylesheet type='text/xsl' href='brag.xsl'?>\n"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
122 |
printTree($buildStatus->[0]); |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
123 |
print "\n"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
124 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
125 |
exit(0); |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
126 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
127 |
sub printTree |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
128 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
129 |
my $tree = shift or die; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
130 |
die unless ref $tree; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
131 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
132 |
my $tagName = ref $tree; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
133 |
$tagName =~ s{^main::}{}; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
134 |
if ($tagName eq "Characters") |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
135 |
{ |
580
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
136 |
print escapeForXML($tree->{Text}); |
572
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
137 |
return; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
138 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
139 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
140 |
print "<$tagName"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
141 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
142 |
foreach my $attr ( |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
143 |
sort { |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
144 |
my $order = "name level start stop href"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
145 |
my $ixA = index $order, $a; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
146 |
my $ixB = index $order, $b; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
147 |
die "$a $b" if $ixA + $ixB == -2; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
148 |
$ixA - $ixB; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
149 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
150 |
grep { |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
151 |
! ref $tree->{$_} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
152 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
153 |
keys %$tree) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
154 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
155 |
print " $attr=\"$tree->{$attr}\""; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
156 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
157 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
158 |
my $children = $tree->{Kids} || []; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
159 |
if (scalar @$children) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
160 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
161 |
print ">"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
162 |
foreach my $child (@$children) |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
163 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
164 |
printTree($child); |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
165 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
166 |
print "</$tagName"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
167 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
168 |
else |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
169 |
{ |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
170 |
print "/" |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
171 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
172 |
|
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
173 |
print ">"; |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
174 |
} |
974b8ee5b70e
Added framework script for turning log files into XML BRAG summaries.
Simon Howkins <simonh@symbian.org>
parents:
diff
changeset
|
175 |
|
580
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
176 |
sub escapeForXML |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
177 |
{ |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
178 |
$_ = shift; |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
179 |
s{&}{&}g; |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
180 |
s{<}{<}g; |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
181 |
s{>}{>}g; |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
182 |
return $_; |
0a42a7ed6d8d
Added XML escaping, so that the output should be well-formed XML even if the input includes '<'s, '>'s, or '&'s.
Simon Howkins <simonh@symbian.org>
parents:
579
diff
changeset
|
183 |
} |