--- loncom/build/filecompare.pl 2001/11/17 21:29:24 1.7 +++ loncom/build/filecompare.pl 2002/02/05 00:52:08 1.11 @@ -1,15 +1,38 @@ #!/usr/bin/perl # The LearningOnline Network with CAPA -# # filecompare.pl - script used to help probe and compare file statistics # +# $Id: filecompare.pl,v 1.11 2002/02/05 00:52:08 harris41 Exp $ +# +# 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 # 9/27, 10/24, 10/25, 11/4 Scott Harrison # 11/14 Guy Albertelli -# 11/16 Scott Harrison +# 11/16,11/17 Scott Harrison +# 12/3,12/5 Scott Harrison # -# $Id: filecompare.pl,v 1.7 2001/11/17 21:29:24 harris41 Exp $ ### ############################################################################### @@ -34,6 +57,9 @@ my $invocation=< 1; age<0 --> 2 N=4: cvstime>0 --> 2 + +The third way to pass arguments is set by the -s flag. +filecompare.pl -s SOURCE=[source] TARGET=[target] MODE=[mode] LOC1 LOC2 + +TARGET corresponds to the root path of LOC2. SOURCE corresponds to +the root path of LOC1. MODE can either be file, directory, link, or fileglob. + END unless (@ARGV) { print $invocation; @@ -92,9 +125,12 @@ unless (@ARGV) { # -q only show file names (based on first file/dir) # -v verbose mode (default) # -bN build/install mode (returns exitcode) +# -s status checking mode for lpml + my $verbose='1'; my $show='all'; my $buildmode=0; +my $statusmode=0; ALOOP: while (@ARGV) { my $flag; if ($ARGV[0]=~/^\-(\w)/) { @@ -112,6 +148,7 @@ ALOOP: while (@ARGV) { $show='same', last SWITCH if $flag eq 'p'; $show='different', last SWITCH if $flag eq 'n'; $show='all', last SWITCH if $flag eq 'a'; + $statusmode=1, last SWITCH if $flag eq 's'; print($invocation), exit(1); } } @@ -122,13 +159,43 @@ ALOOP: while (@ARGV) { dowarn('Verbose: '.$verbose."\n"); dowarn('Show: '.$show."\n"); +my @files; +my $loc1; +my $loc2; +my $dirmode='directories'; +# ----------------------------------------- If status checking mode for lpml +my ($sourceroot,$targetroot,$mode,$sourceglob,$targetglob); +my ($source,$target); +if ($statusmode==1) { + ($sourceroot,$targetroot,$mode,$sourceglob,$targetglob)=splice(@ARGV,0,5); + $targetroot.='/' if $targetroot!~/\/$/; + $sourceroot=~s/^SOURCE\=//; + $targetroot=~s/^TARGET\=//; + $source=$sourceroot.'/'.$sourceglob; + $target=$targetroot.''.$targetglob; +# print "SOURCE: $source\n"; +# print "TARGET: $target\n"; + if ($mode eq 'MODE=fileglob') { + $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 { + # ----------------------------------------- Process file/dir location arguments # FILE1 FILE2 or DIR1 DIR2 -my $loc1=shift @ARGV; -my $loc2=shift @ARGV; -my $dirmode='directories'; -my @files; +$loc1=shift @ARGV; +$loc2=shift @ARGV; unless ($loc1 and $loc2) { + print "LOC1: $loc1\nLOC2: $loc2\n"; print($invocation), exit(1); } if (-f $loc1) { @@ -147,7 +214,7 @@ else { dowarn('Processing for mode: '.$dirmode."\n"); dowarn('Location #1: '.$loc1."\n"); dowarn('Location #2: '.$loc2."\n"); - +} # --------------------------------------------- Process comparison restrictions # A list of space separated values (after the file/dir names) # can restrict the comparison. @@ -436,12 +503,18 @@ sub cvstime { } my $cvstime; if ($buildmode!=3) { - my $entry=`grep '^/$file/' ${path}CVS/Entries` or - die('*** ERROR *** cannot grep against '.${path}. - 'CVS/Entries for ' .$file . "\n"); - my @fields=split(/\//,$entry); - $cvstime=`date -d '$fields[3] UTC' --utc +"%s"`; - chomp $cvstime; + my $entry=`grep '^/$file/' ${path}CVS/Entries`; +# or +# die('*** WARNING *** cannot grep against '.${path}. +# 'CVS/Entries for ' .$file . "\n"); + if ($entry) { + my @fields=split(/\//,$entry); + $cvstime=`date -d '$fields[3] UTC' --utc +"%s"`; + chomp $cvstime; + } + else { + $cvstime='n/a'; + } } else { $cvstime='n/a';