scripts/commit_count/commits.pl
changeset 29 13a99a13ca90
equal deleted inserted replaced
28:ab800b3e45ab 29:13a99a13ca90
       
     1 #!/usr/bin/perl
       
     2 
       
     3 use Getopt::Long;
       
     4 my $log_file;
       
     5 my $log_data;
       
     6 
       
     7 
       
     8 
       
     9 
       
    10 sub printhelp
       
    11 {
       
    12   print "\ncounting commits in log file
       
    13   \noptions:
       
    14   \n\t-f (mandaory) mercurial access log file\n";
       
    15   exit;
       
    16 
       
    17 }
       
    18 
       
    19 sub cmd_options
       
    20 {
       
    21 
       
    22   my $help;
       
    23   
       
    24 
       
    25 
       
    26   GetOptions('h' => \$help,'f=s'=> \$log_file);
       
    27 
       
    28   
       
    29   if ($help) {
       
    30     printhelp;
       
    31   }
       
    32   
       
    33   if (not $log_file) {
       
    34     print "ERROR  - LOG File not provided\n ";
       
    35     printhelp;
       
    36   }
       
    37 
       
    38                                     
       
    39 
       
    40 }
       
    41 
       
    42 
       
    43 #main
       
    44 cmd_options();
       
    45 
       
    46 open(DATA, "<".$log_file);
       
    47 open(COMMITOUT, ">output_commits.csv");
       
    48 
       
    49 while (<DATA>){
       
    50      $log_data = $_;
       
    51      if ($log_data =~ m/POST/ & $log_data =~ m/MCL(.*?)\?.*?\" 200 /)  { 
       
    52         $pkg = $1;
       
    53         if ($log_data =~ m/([0-9]+)\/([A-z]+)\/([0-9]+)/) {
       
    54           
       
    55           $tcommit = $1."-".$2."-".$3;   
       
    56             
       
    57         } else {
       
    58           $tcommit = "NOTFOUND_TIME";
       
    59         }
       
    60         
       
    61         if ($log_data =~ m/(\d+\.\d+\.\d+\.\d+)/) {
       
    62           
       
    63           $ipcommit = $1;   
       
    64             
       
    65         } else {
       
    66           $ipcommit = "NOTFOUND_IP";
       
    67         }
       
    68         
       
    69         
       
    70         print COMMITOUT "$pkg\t$tcommit\t$ipcommit\n"; 
       
    71      }
       
    72 
       
    73 }
       
    74 
       
    75 close (DATA);
       
    76 close (COMMITOUT);