common/tools/brag/raptorToBRAG.pl
changeset 613 f2e526e44405
parent 605 2907b286c72a
child 665 ddca63d8e13c
equal deleted inserted replaced
612:78ccc60a13b1 613:f2e526e44405
    35 	exit(0);
    35 	exit(0);
    36 }
    36 }
    37 
    37 
    38 # Start to build structure to be output as XML (same format as XML::Parser would create for us)
    38 # Start to build structure to be output as XML (same format as XML::Parser would create for us)
    39 my $xmlNewline = bless { Text => "\n" }, "Characters";
    39 my $xmlNewline = bless { Text => "\n" }, "Characters";
    40 my $data = [bless {name => "build", Kids => [ $xmlNewline ] }, "stage"];
    40 my $buildStatus =
       
    41 [
       
    42 	bless
       
    43 	{
       
    44 		Kids =>
       
    45 		[
       
    46 			$xmlNewline,
       
    47 			bless
       
    48 			{
       
    49 				name => "Build",
       
    50 				Kids => [ $xmlNewline ]
       
    51 			}, "phase",
       
    52 		]
       
    53 	}, "buildStatus"
       
    54 ];
    41 # Get a shortcut reference to the bit we will use a lot
    55 # Get a shortcut reference to the bit we will use a lot
    42 my $buildStage = $data->[0];
    56 my $buildPhase = $buildStatus->[0]->{Kids}->[-1];
    43 
    57 
    44 # READ SUMMARY.CSV FILE
    58 # READ SUMMARY.CSV FILE
    45 open(CSV, $raptorSummary);
    59 open(CSV, $raptorSummary);
    46 my $csv = Text::CSV->new();
    60 my $csv = Text::CSV->new();
    47 while (my $line = <CSV>)
    61 while (my $line = <CSV>)
    61 	{
    75 	{
    62 		warn "WARNING: line does not match expected format at $raptorSummary line $.. Skipping\n";
    76 		warn "WARNING: line does not match expected format at $raptorSummary line $.. Skipping\n";
    63 		next;
    77 		next;
    64 	}
    78 	}
    65 	
    79 	
       
    80 	# Populate the hash using a hash slice
    66 	my $failure = {};
    81 	my $failure = {};
    67 	@{$failure}{@keys} = @values;
    82 	@{$failure}{@keys} = @values;
    68 	
    83 	
    69 	if (!$failure->{category})
    84 	if (!$failure->{category})
    70 	{
    85 	{
    80 	$failure->{subcategory} ||= 'uncategorized';
    95 	$failure->{subcategory} ||= 'uncategorized';
    81 	$failure->{severity} ||= 'unknown';
    96 	$failure->{severity} ||= 'unknown';
    82 	
    97 	
    83 	# Look through the steps to see if we already have one to match this config
    98 	# Look through the steps to see if we already have one to match this config
    84 	my $step;
    99 	my $step;
    85 	foreach (@{$buildStage->{Kids}})
   100 	foreach (@{$buildPhase->{Kids}})
    86 	{
   101 	{
    87 		next unless ref $_ eq "step";
   102 		next unless ref $_ eq "step";
    88 		if ($_->{name} eq $failure->{config})
   103 		if ($_->{name} eq $failure->{config})
    89 		{
   104 		{
    90 			$step = $_;
   105 			$step = $_;
    93 	}
   108 	}
    94 	unless ($step)
   109 	unless ($step)
    95 	{
   110 	{
    96 		# First item found in this step - create step entry
   111 		# First item found in this step - create step entry
    97 		$step = bless { name => $failure->{config}, Kids => [ $xmlNewline ] }, "step";
   112 		$step = bless { name => $failure->{config}, Kids => [ $xmlNewline ] }, "step";
    98 		push @{$buildStage->{Kids}}, $step, $xmlNewline;
   113 		push @{$buildPhase->{Kids}}, $step, $xmlNewline;
       
   114 		# Also create empty <failures> tags with severities in a sensible order
       
   115 		foreach my $severity (qw{critical major minor})
       
   116 		{
       
   117 			my $failureSet = bless { level => $severity, Kids => [ $xmlNewline ] }, "failures";
       
   118 			push @{$step->{Kids}}, $failureSet, $xmlNewline;
       
   119 		}
    99 	}
   120 	}
   100 	
   121 	
   101 	# Look through the sets of failures in this step to see if we hve one which matches this severity
   122 	# Look through the sets of failures in this step to see if we hve one which matches this severity
   102 	my $failureSet;
   123 	my $failureSet;
   103 	foreach (@{$step->{Kids}})
   124 	foreach (@{$step->{Kids}})
   115 		$failureSet = bless { level => $failure->{severity}, Kids => [ $xmlNewline ] }, "failures";
   136 		$failureSet = bless { level => $failure->{severity}, Kids => [ $xmlNewline ] }, "failures";
   116 		push @{$step->{Kids}}, $failureSet, $xmlNewline;
   137 		push @{$step->{Kids}}, $failureSet, $xmlNewline;
   117 	}
   138 	}
   118 
   139 
   119 	# Now create the failure itself, and add it to this failure set
   140 	# Now create the failure itself, and add it to this failure set
   120 	my $failureItem = bless { href => "", Kids => [ bless { Text => $failure->{subcategory} }, "Characters" ] }, "failure";
   141 	my $failureItem = bless {
       
   142 #		href => "",
       
   143 		Kids => [ bless { Text => $failure->{subcategory} }, "Characters" ]
       
   144 	}, "failure";
       
   145 	if ($failure->{component})
       
   146 	{
       
   147 		$failure->{component} =~ s{^(/sf/.*?/.*?)/.*$}{$1};
       
   148 		$failureItem->{package} = $failure->{component};
       
   149 	}
   121 	push @{$failureSet->{Kids}}, $failureItem, $xmlNewline;
   150 	push @{$failureSet->{Kids}}, $failureItem, $xmlNewline;
   122 }
   151 }
   123 close(CSV);
   152 close(CSV);
   124 
   153 
   125 # Print XML
   154 # Print XML
   126 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   155 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   127 print "<?xml-stylesheet type='text/xsl' href='brag.xsl'?>\n";
   156 print "<?xml-stylesheet type='text/xsl' href='brag.xsl'?>\n";
   128 printTree($data->[0]);
   157 printTree($buildStatus->[0]);
   129 print "\n";
   158 print "\n";
   130 
   159 
   131 exit(0);
   160 exit(0);
   132 
   161 
   133 sub printTree
   162 sub printTree