common/tools/uh2diamonds.pl
changeset 1050 34dcbee2af5e
child 1051 044ab1b95cae
equal deleted inserted replaced
1049:106264ed9735 1050:34dcbee2af5e
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 # Initial Contributors:
       
     8 # Symbian Foundation Ltd - initial contribution.
       
     9 #
       
    10 # Contributors:
       
    11 #
       
    12 # Description:
       
    13 # Translates uh report (index.html) to a Diamonds file
       
    14 
       
    15 use strict;
       
    16 
       
    17 use Getopt::Long;
       
    18 
       
    19 my $input = "\\output\\logs\\html\\index.html";
       
    20 my $output = "\\output\\logs\\diamonds_uh.xml";
       
    21 my $help = 0;
       
    22 GetOptions((
       
    23 	'in=s' => \$input,
       
    24 	'out=s' => \$output,
       
    25 	'help!' => \$help
       
    26 ));
       
    27 
       
    28 if ($help)
       
    29 {
       
    30 	print "Translates uh report (index.html) to a Diamonds file\n";
       
    31 	print "Usage: perl uh2diamonds.pl [--in=UHINDEX] [--out=XMLFILE]\n";
       
    32 	print "\n";
       
    33 	print "UHINDEX is optional, its default is \\output\\logs\\html\\index.html\n";
       
    34 	print "XMLFILE is optional, its default is \\output\\logs\\diamonds_uh.xml\n";
       
    35 	exit(0);
       
    36 }
       
    37 
       
    38 my $critical = 0;
       
    39 my $major = 0;
       
    40 my $minor = 0;
       
    41 my $unknown = 0;
       
    42 my $missing = 0;
       
    43 
       
    44 open(INDEX, $input) or die "Can't open $input for reading";
       
    45 while (<INDEX>)
       
    46 {
       
    47 	my $line = $_;
       
    48 	if ($line =~ m,<tr><td><a href='.*'>\w+</a></td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr>,)
       
    49 	{
       
    50 		$critical += $1;
       
    51 		$major += $2;
       
    52 		$minor += $3;
       
    53 		$unknown += $4;
       
    54 	}
       
    55 	elsif($line =~ m,<tr><td><a href='.+'>.+</a></td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr>,)
       
    56 	{
       
    57 		$critical += $1;
       
    58 		$major += $2;
       
    59 		$minor += $3;
       
    60 		$unknown += $4;
       
    61 		$missing += $5;
       
    62 	}
       
    63 }
       
    64 close(INDEX);
       
    65 
       
    66 my $xml_content = <<_EOX;
       
    67 
       
    68 <?xml version=\"1.0\" encoding=\"utf-8\"?>
       
    69 <diamonds-build>
       
    70   <schema>14</schema>
       
    71   <faults>
       
    72     <total severity=\"Raptor Build Critical\">$critical</total>
       
    73     <total severity=\"Raptor Build Major\">$major</total>
       
    74     <total severity=\"Raptor Build Minor\">$minor</total>
       
    75     <total severity=\"Raptor Build Unknown\">$unknown</total>
       
    76     <total severity=\"Missing Artifacts\">$missing</total>
       
    77   </faults>
       
    78 </diamonds-build>
       
    79 _EOX
       
    80 
       
    81 if (open(XML, ">$output"))
       
    82 {
       
    83 	print XML $xml_content;
       
    84 	close(XML);
       
    85 	print "Wrote Diamonds file: $output\n";
       
    86 }
       
    87 else
       
    88 {
       
    89 	warn "Could not write to file: $output\n";
       
    90 }