Diff for /loncom/build/filecompare.pl between versions 1.9 and 1.14

version 1.9, 2001/12/06 00:23:16 version 1.14, 2004/07/02 22:04:50
Line 1 Line 1
 #!/usr/bin/perl  #!/usr/bin/perl
   
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 #  
 # filecompare.pl - script used to help probe and compare file statistics  # filecompare.pl - script used to help probe and compare file statistics
 #  #
   # $Id$
   #
   # Copyright Michigan State University Board of Trustees
   #
   # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   #
   # LON-CAPA is free software; you can redistribute it and/or modify
   # it under the terms of the GNU General Public License as published by
   # the Free Software Foundation; either version 2 of the License, or
   # (at your option) any later version.
   #
   # LON-CAPA is distributed in the hope that it will be useful,
   # but WITHOUT ANY WARRANTY; without even the implied warranty of
   # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   # GNU General Public License for more details.
   #
   # You should have received a copy of the GNU General Public License
   # along with LON-CAPA; if not, write to the Free Software
   # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   #
   # /home/httpd/html/adm/gpl.txt
   #
   # http://www.lon-capa.org/
   #
 # YEAR=2001  # YEAR=2001
 # 9/27, 10/24, 10/25, 11/4 Scott Harrison  # 9/27, 10/24, 10/25, 11/4 Scott Harrison
 # 11/14 Guy Albertelli  # 11/14 Guy Albertelli
 # 11/16,11/17 Scott Harrison  # 11/16,11/17 Scott Harrison
 # 12/3,12/5 Scott Harrison  # 12/3,12/5 Scott Harrison
 #  #
 # $Id$  
 ###  ###
   
 ###############################################################################  ###############################################################################
Line 50  Options (before file/dir names): Line 72  Options (before file/dir names):
 -a show all files (with comparisons)  -a show all files (with comparisons)
 -q only show file names (based on first file/dir)  -q only show file names (based on first file/dir)
 -v verbose mode (default)  -v verbose mode (default)
 -bN buildmode (controls exit code of this script; 0 unless...)  -bN buildmode (controls EXIT code of this script; 0 unless...)
    N=1: md5sum=same --> 1; cvstime<0 --> 2     N=1: md5sum=same --> 1; cvstime<0 --> 2
    N=2: same as N=1 except without md5sum     N=2: same as N=1 except without md5sum
    N=3: md5sum=same --> 1; age<0 --> 2     N=3: md5sum=same --> 1; age<0 --> 2
Line 140  dowarn('Show: '.$show."\n"); Line 162  dowarn('Show: '.$show."\n");
 my @files;  my @files;
 my $loc1;  my $loc1;
 my $loc2;  my $loc2;
   my $dirmode='directories';
 # ----------------------------------------- If status checking mode for lpml  # ----------------------------------------- If status checking mode for lpml
 my ($sourceroot,$targetroot,$mode,$sourceglob,$targetglob);  my ($sourceroot,$targetroot,$mode,$sourceglob,$targetglob);
 my ($source,$target);  my ($source,$target);
Line 153  if ($statusmode==1) { Line 176  if ($statusmode==1) {
 #    print "SOURCE: $source\n";  #    print "SOURCE: $source\n";
 #    print "TARGET: $target\n";  #    print "TARGET: $target\n";
     if ($mode eq 'MODE=fileglob') {      if ($mode eq 'MODE=fileglob') {
  @files=glob($source);   $loc1=$source;$loc1=~s/\/[^\/]*$// if length($loc1)>2;
    $loc2=$target;$loc2=~s/\/[^\/]*$// if length($loc2)>2;
    @files=map {s/^$loc1\///;$_} glob($source);
    $dirmode='directories';
       }
       elsif ($mode eq 'MODE=file') {
    $loc1=$source;
    $loc2=$target;
    $dirmode='files';
    @files=($loc1);
     }      }
 }  }
 else {  else {
Line 162  else { Line 194  else {
 # FILE1 FILE2 or DIR1 DIR2  # FILE1 FILE2 or DIR1 DIR2
 $loc1=shift @ARGV;  $loc1=shift @ARGV;
 $loc2=shift @ARGV;  $loc2=shift @ARGV;
 my $dirmode='directories';  
 unless ($loc1 and $loc2) {  unless ($loc1 and $loc2) {
     print "LOC1: $loc1\nLOC2: $loc2\n";      print "LOC1: $loc1\nLOC2: $loc2\n";
     print($invocation), exit(1);      print($invocation), exit(1);
Line 238  my %MEASURE=( Line 269  my %MEASURE=(
  my $rv2=`wc -l $file2`; chop $rv2;   my $rv2=`wc -l $file2`; chop $rv2;
  return ($rv1,$rv2); } ),   return ($rv1,$rv2); } ),
          'diffs'=>( sub { my ($file1,$file2)=@_;           'diffs'=>( sub { my ($file1,$file2)=@_;
    return (0,0);
  my $rv1=`diff $file1 $file2 | grep '^<' | wc -l`;   my $rv1=`diff $file1 $file2 | grep '^<' | wc -l`;
  chop $rv1; $rv1=~s/^\s+//; $rv1=~s/\s+$//;   chop $rv1; $rv1=~s/^\s+//; $rv1=~s/\s+$//;
  my $rv2=`diff $file1 $file2 | grep '^>' | wc -l`;   my $rv2=`diff $file1 $file2 | grep '^>' | wc -l`;
Line 392  FLOOP: foreach my $file (@files) { Line 424  FLOOP: foreach my $file (@files) {
     $showflag=1;      $showflag=1;
  }   }
     }      }
     if ($buildmode==1) {      if ($buildmode==1) { # -b1
         if ($md5sum eq 'same') {          if ($md5sum eq 'same') {
     exit(1);      exit(1);
  }   }
Line 403  FLOOP: foreach my $file (@files) { Line 435  FLOOP: foreach my $file (@files) {
     exit(0);      exit(0);
  }   }
     }      }
     elsif ($buildmode==2) {      elsif ($buildmode==2) { # -b2
         if ($cvstime<0) {          if ($cvstime<0) {
     exit(2);      exit(2);
  }   }
Line 411  FLOOP: foreach my $file (@files) { Line 443  FLOOP: foreach my $file (@files) {
     exit(0);      exit(0);
  }   }
     }      }
     elsif ($buildmode==3) {      elsif ($buildmode==3) { # -b3
         if ($md5sum eq 'same') {          if ($md5sum eq 'same') {
     exit(1);      exit(1);
  }   }
Line 422  FLOOP: foreach my $file (@files) { Line 454  FLOOP: foreach my $file (@files) {
     exit(0);      exit(0);
  }   }
     }      }
     elsif ($buildmode==4) {      elsif ($buildmode==4) { # -b4
  if ($existence=~/no$/) {   if ($existence=~/no$/) {
     exit(3);      exit(3);
  }   }
Line 472  sub cvstime { Line 504  sub cvstime {
     }      }
     my $cvstime;      my $cvstime;
     if ($buildmode!=3) {      if ($buildmode!=3) {
  my $entry=`grep '^/$file/' ${path}CVS/Entries` or   my $entry=`grep '^/$file/' ${path}CVS/Entries 2>/dev/null`;
     die('*** ERROR *** cannot grep against '.${path}.  # or
  'CVS/Entries for ' .$file . "\n");  #    die('*** WARNING *** cannot grep against '.${path}.
         my @fields=split(/\//,$entry);  # 'CVS/Entries for ' .$file . "\n");
         $cvstime=`date -d '$fields[3] UTC' --utc +"%s"`;   if ($entry) {
         chomp $cvstime;      my @fields=split(/\//,$entry);
       $cvstime=`date -d '$fields[3] UTC' --utc +"%s"`;
       chomp $cvstime;
    }
    else {
       $cvstime='n/a';
    }
     }      }
     else {      else {
  $cvstime='n/a';   $cvstime='n/a';

Removed from v.1.9  
changed lines
  Added in v.1.14


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>