common/tools/analysis/merge_csv_orphans.pl
changeset 127 5274345d5497
equal deleted inserted replaced
122:5639fead6fba 127:5274345d5497
       
     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 my $zipfile = shift @ARGV;
       
    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 %ziptimes;
       
    33         my %zipused;
       
    34         if(defined $zipfile)
       
    35           {
       
    36           open(ZIP,"7z l $zipfile 2>&1|")  or die "Error: Couldn't look in $zipfile\n";
       
    37 #          print "time,file\n";
       
    38           while( my $line = <ZIP>)
       
    39             {
       
    40             if($line =~ m/^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s\S{5}\s+(\d+)\s+\d+\s+(.+)$/) #ignoring packed size...
       
    41               {
       
    42               my $name = $3;
       
    43               my $size = $2;
       
    44               my $time = $1;
       
    45               $name =~ s/\\/\//g;
       
    46               $name = lc($name);
       
    47               $ziptimes{$name} = $time;
       
    48 #              print "$time,$name\n";
       
    49               }
       
    50             }
       
    51           close ZIP;
       
    52           }
       
    53         my %files;
       
    54 
       
    55         open(FILES,"<$filelist") or die "Couldn't open $filelist\n";
       
    56         while(my $line = <FILES>)
       
    57         {
       
    58             $line =~ s/\\/\//g;
       
    59 
       
    60             if($line =~ m/^(.+)\s*:\s(.+\S)\s*$/)
       
    61             {
       
    62                 my $group = $1;
       
    63                 my $file = $2;
       
    64 
       
    65                 $file = lc($file);
       
    66                 if($files{$file})
       
    67                 {
       
    68            
       
    69                     $files{$file} = $files{$file}." ".$group; #Stop polluting next column                                        
       
    70                        print "Multi:$file".$files{$file}."\n";
       
    71 
       
    72                 }
       
    73                 else
       
    74                 {
       
    75                      $files{$file} = ",".$group;
       
    76                 }
       
    77             }                
       
    78         }
       
    79         close FILE;
       
    80 
       
    81         open(CSV,"<$csvfile") or die "Couldn't open $csvfile\n";
       
    82         my $resultsfile = $csvfile."_results.csv"; 
       
    83         open(RESULTS,">$resultsfile") or die "Couldn't open write to $resultsfile\n";
       
    84         my $header = <CSV>;
       
    85         $header =~ s/\n//;
       
    86         print RESULTS $header.",status,time\n";
       
    87         my @fields = split(',',$header);
       
    88         my $targetindex = 0;
       
    89         my $counter = 0;
       
    90         my $bldinfindex = 0;
       
    91         my %failed;
       
    92         my %bldinffiles;
       
    93         foreach my $column (@fields)
       
    94         {
       
    95             if($column =~ m/target/)
       
    96             {
       
    97                 $targetindex = $counter;
       
    98             }
       
    99             elsif($column =~ m/bldinf/)
       
   100             {
       
   101               $bldinfindex = $counter;
       
   102             }
       
   103             ++$counter;
       
   104         }
       
   105         ++$counter;
       
   106         my $timeindex = $counter;
       
   107 #        print "\ntarget:$targetindex\tbuildinf:$bldinfindex\n";
       
   108         while(my $line = <CSV>)
       
   109             {
       
   110             $line =~ s/\n//;
       
   111             @fields = split(',',$line);
       
   112             my $target = $fields[$targetindex];
       
   113             $target = lc($target);
       
   114             my $bldinf = $fields[$bldinfindex];
       
   115             if(!defined $bldinffiles{$bldinf})
       
   116             {
       
   117               $bldinffiles{$bldinf} = 1;
       
   118             }
       
   119             my $found = 0; 
       
   120             if(defined $files{$target})
       
   121                 {
       
   122                     $found = 1;                    
       
   123                     $line = $line.$files{$target};
       
   124                     if($files{$target} =~ m/fail/i)
       
   125                     {
       
   126                       if(!defined $failed{$bldinf})
       
   127                       {
       
   128                         $failed{$bldinf} = 1;
       
   129                       }
       
   130                     }
       
   131                 }
       
   132             if(defined $ziptimes{$target})
       
   133               {
       
   134                 $zipused{$target} = 1;
       
   135                 if($found)
       
   136                 {
       
   137                   $line = $line.",".$ziptimes{$target};
       
   138                 }
       
   139                 else
       
   140                 {
       
   141                   $line = $line.",,".$ziptimes{$target};
       
   142                 }
       
   143               }     
       
   144             print RESULTS $line."\n";
       
   145             
       
   146             }            
       
   147         close CSV;
       
   148         
       
   149         foreach my $target (sort(keys %ziptimes))
       
   150         {
       
   151 
       
   152           if(!defined $zipused{$target})
       
   153           {
       
   154             my $time = $ziptimes{$target};
       
   155             my $columnCounter=0;
       
   156             my @row;
       
   157             while($columnCounter <= $counter)
       
   158             {
       
   159               if($columnCounter == $bldinfindex)
       
   160               {
       
   161                 push(@row,"Orphaned,");
       
   162               }
       
   163               elsif($columnCounter == $targetindex)
       
   164               {
       
   165                 push(@row,"$target,");
       
   166               }
       
   167               elsif($columnCounter == $timeindex-1)
       
   168               {
       
   169                 push(@row,"untouched,");
       
   170               }
       
   171               elsif($columnCounter == $timeindex)
       
   172               {
       
   173                 push(@row,"$time,");
       
   174               }              
       
   175               else
       
   176               {
       
   177                 push(@row,",");
       
   178               }
       
   179               ++$columnCounter;
       
   180             }
       
   181             print RESULTS @row;
       
   182             print RESULTS "\n";
       
   183           }
       
   184         }  
       
   185         close RESULTS;
       
   186 
       
   187         foreach my $bldinf (sort(keys %bldinffiles))
       
   188         {
       
   189           if(!defined $failed{$bldinf})
       
   190           {
       
   191             print "OK:\t$bldinf\n";
       
   192           }
       
   193         }
       
   194         foreach my $bldinf (sort(keys %failed))
       
   195         {
       
   196             print "Failed:\t$bldinf\n";
       
   197         }
       
   198