common/tools/analysis/merge_csv.pl
changeset 97 4f54ca96b7e8
child 121 fc757bffbe1d
equal deleted inserted replaced
93:27826401fee5 97:4f54ca96b7e8
       
     1 #!/usr/bin/perl
       
     2 
       
     3 # Copyright (c) 2009 Symbian Foundation Ltd
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Symbian Foundation Ltd - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Adds info form a file to a CSV
       
    16 
       
    17 use strict;
       
    18 my $csvfile = shift @ARGV;
       
    19 my $filelist = shift @ARGV;
       
    20 
       
    21 
       
    22 if(! -e $csvfile)
       
    23 {
       
    24   die "cannot find $csvfile\n";
       
    25 }
       
    26 
       
    27   
       
    28 if(!-e $filelist)
       
    29 {
       
    30   die "Cannot find $filelist\n";
       
    31 }
       
    32         my %files;
       
    33         open(FILES,"<$filelist") or die "Couldn't open $filelist\n";
       
    34         while(my $line = <FILES>)
       
    35         {
       
    36             $line =~ s/\\/\//g;
       
    37 
       
    38             if($line =~ m/^(.+)\s*:\s(.+\S)\s*$/)
       
    39             {
       
    40                 my $group = $1;
       
    41                 my $file = $2;
       
    42 
       
    43                 $file = lc($file);
       
    44                 if($files{$file})
       
    45                 {
       
    46            
       
    47                     $files{$file} = $files{$file}.",".$group;                                        
       
    48                        print "Multi:$file".$files{$file}."\n";
       
    49 
       
    50                 }
       
    51                 else
       
    52                 {
       
    53                      $files{$file} = ",".$group;
       
    54                 }
       
    55             }                
       
    56         }
       
    57         close FILE;
       
    58 
       
    59         open(CSV,"<$csvfile") or die "Couldn't open $csvfile\n";
       
    60         my $resultsfile = $csvfile."_results.csv"; 
       
    61         open(RESULTS,">$resultsfile") or die "Couldn't open write to $resultsfile\n";
       
    62         my $header = <CSV>;
       
    63         $header =~ s/\n//;
       
    64         print RESULTS $header.",status\n";
       
    65         my @fields = split(',',$header);
       
    66         my $targetindex = 0;
       
    67         my $counter = 0;
       
    68         my $bldinfindex = 0;
       
    69         
       
    70         my %failed;
       
    71         my %bldinffiles;
       
    72         foreach my $column (@fields)
       
    73         {
       
    74             if($column =~ m/target/)
       
    75             {
       
    76                 $targetindex = $counter;
       
    77             }
       
    78             elsif($column =~ m/bldinf/)
       
    79             {
       
    80               $bldinfindex = $counter;
       
    81             }
       
    82             ++$counter;
       
    83         }
       
    84 #        print "\ntarget:$targetindex\tbuildinf:$bldinfindex\n";
       
    85         while(my $line = <CSV>)
       
    86             {
       
    87             $line =~ s/\n//;
       
    88             @fields = split(',',$line);
       
    89             my $target = $fields[$targetindex];
       
    90             $target = lc($target);
       
    91             my $bldinf = $fields[$bldinfindex];
       
    92             if(!defined $bldinffiles{$bldinf})
       
    93             {
       
    94               $bldinffiles{$bldinf} = 1;
       
    95             }
       
    96  
       
    97             if(defined $files{$target})
       
    98                 {                    
       
    99                     $line = $line.$files{$target};
       
   100                     if($files{$target} =~ m/fail/i)
       
   101                     {
       
   102                       if(!defined $failed{$bldinf})
       
   103                       {
       
   104                         $failed{$bldinf} = 1;
       
   105                       }
       
   106                     }
       
   107                 }
       
   108             print RESULTS $line."\n";
       
   109             
       
   110             }            
       
   111         close RESULTS;
       
   112         close CSV;
       
   113         foreach my $bldinf (sort(keys %bldinffiles))
       
   114         {
       
   115           if(!defined $failed{$bldinf})
       
   116           {
       
   117             print "OK:\t$bldinf\n";
       
   118           }
       
   119         }
       
   120         foreach my $bldinf (sort(keys %failed))
       
   121         {
       
   122             print "Failed:\t$bldinf\n";
       
   123         }
       
   124