version 1.4, 2001/11/16 20:06:08
|
version 1.5, 2001/11/16 21:12:46
|
Line 1
|
Line 1
|
#!/usr/bin/perl |
#!/usr/bin/perl |
|
|
# The LearningOnline Network witih 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 |
# |
# |
Line 12
|
Line 12
|
# $Id$ |
# $Id$ |
### |
### |
|
|
|
############################################################################### |
|
## ## |
|
## ORGANIZATION OF THIS PERL SCRIPT ## |
|
## ## |
|
## 1. Invocation ## |
|
## 2. Notes ## |
|
## 3. Dependencies ## |
|
## 4. Process command line arguments ## |
|
## 5. Process file/dir location arguments ## |
|
## 6. Process comparison restrictions ## |
|
## 7. Define output and measure subroutines ## |
|
## 8. Loop through files and calculate differences ## |
|
## 9. Subroutines ## |
|
## 10. POD (plain old documentation, CPAN style) ## |
|
## ## |
|
############################################################################### |
|
|
# ------------------------------------------------------------------ Invocation |
# ------------------------------------------------------------------ Invocation |
my $invocation=<<END; |
my $invocation=<<END; |
filecompare.pl [ options ... ] [FILE1] [FILE2] [ restrictions ... ] |
filecompare.pl [ options ... ] [FILE1] [FILE2] [ restrictions ... ] |
Line 29 Options (before file/dir names):
|
Line 46 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...) |
|
N=1: md5sum=same --> 2; cvstime<0 --> 1 |
|
N=2: same as N=1 except without md5sum |
|
N=3: md5sum=same --> 1; age<0 --> 2 |
|
N=4: cvstime>0 --> 2 |
END |
END |
unless (@ARGV) { |
unless (@ARGV) { |
print $invocation; |
print $invocation; |
exit 1; |
exit 1; |
} |
} |
|
|
# ----------------------------------------------------------------------- Notes |
# ----------------------------------------------------------------------- Notes |
# |
# |
# What are all the different ways to compare two files and how to look |
# What are all the different ways to compare two files and how to look |
Line 56 unless (@ARGV) {
|
Line 79 unless (@ARGV) {
|
# size similarity (byte difference) |
# size similarity (byte difference) |
# line count difference (integer) |
# line count difference (integer) |
# number of different lines (integer) |
# number of different lines (integer) |
# |
|
# Text output of comparison: |
|
# existence VALUE |
|
# cvstime VALUE |
|
# age VALUE |
|
# md5sum VALUE |
|
# size VALUE |
|
# lines VALUE |
|
# diffs VALUE |
|
# |
|
# Output of comparison: |
|
# exist |
|
# if md5sum not same, then different |
|
# if cvstime not 0, then older/newer |
|
# if age not 0, then older/newer |
|
# if size not 0, then bigger/smaller |
|
# if lines not 0, then more lines of code/less lines of code |
|
# if diffs not 0, then subtracted lines/added lines/changed lines |
|
|
|
|
# ---------------------------------------------------------------- Dependencies |
# implementing from unix command line (assuming bash) |
# implementing from unix command line (assuming bash) |
# md5sum, diff, wc -l |
# md5sum, diff, wc -l |
|
|
Line 85 unless (@ARGV) {
|
Line 91 unless (@ARGV) {
|
# -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) |
# -b build/install mode (returns exitcode) |
# -bN build/install mode (returns exitcode) |
my $verbose='1'; |
my $verbose='1'; |
my $show='all'; |
my $show='all'; |
my $buildmode=0; |
my $buildmode=0; |
Line 93 while (@ARGV) {
|
Line 99 while (@ARGV) {
|
my $flag; |
my $flag; |
if ($ARGV[0]=~/^\-(\w)/) { |
if ($ARGV[0]=~/^\-(\w)/) { |
$flag=$1; |
$flag=$1; |
|
if ($flag eq 'b') { |
|
$ARGV[0]=~/^\-\w(\d)/; |
|
$buildmode=$1; |
|
} |
shift @ARGV; |
shift @ARGV; |
SWITCH: { |
SWITCH: { |
$verbose=0, last SWITCH if $flag eq 'q'; |
$verbose=0, last SWITCH if $flag eq 'q'; |
Line 100 while (@ARGV) {
|
Line 110 while (@ARGV) {
|
$show='same', last SWITCH if $flag eq 'p'; |
$show='same', last SWITCH if $flag eq 'p'; |
$show='different', last SWITCH if $flag eq 'n'; |
$show='different', last SWITCH if $flag eq 'n'; |
$show='all', last SWITCH if $flag eq 'a'; |
$show='all', last SWITCH if $flag eq 'a'; |
$buildmode=1, last SWITCH if $flag eq 'b'; |
|
$buildmode=2, last SWITCH if $flag eq 'B'; |
|
$buildmode=3, last SWITCH if $flag eq 'g'; |
|
$buildmode=4, last SWITCH if $flag eq 'G'; |
|
print($invocation), exit(1); |
print($invocation), exit(1); |
} |
} |
} |
} |
Line 114 while (@ARGV) {
|
Line 120 while (@ARGV) {
|
dowarn('Verbose: '.$verbose."\n"); |
dowarn('Verbose: '.$verbose."\n"); |
dowarn('Show: '.$show."\n"); |
dowarn('Show: '.$show."\n"); |
|
|
|
# ----------------------------------------- Process file/dir location arguments |
# FILE1 FILE2 or DIR1 DIR2 |
# FILE1 FILE2 or DIR1 DIR2 |
my $loc1=shift @ARGV; |
my $loc1=shift @ARGV; |
my $loc2=shift @ARGV; |
my $loc2=shift @ARGV; |
Line 139 dowarn('Processing for mode: '.$dirmode.
|
Line 146 dowarn('Processing for mode: '.$dirmode.
|
dowarn('Location #1: '.$loc1."\n"); |
dowarn('Location #1: '.$loc1."\n"); |
dowarn('Location #2: '.$loc2."\n"); |
dowarn('Location #2: '.$loc2."\n"); |
|
|
|
# --------------------------------------------- Process comparison restrictions |
# A list of space separated values (after the file/dir names) |
# A list of space separated values (after the file/dir names) |
# can restrict the comparison. |
# can restrict the comparison. |
|
my %rhash=('existence'=>0,'cvstime'=>0,'md5sum'=>0,'age'=>0,'size'=>0, |
|
'lines'=>0,'diffs'=>0); |
my %restrict; |
my %restrict; |
while (@ARGV) { |
while (@ARGV) { |
my $r=shift @ARGV; |
my $r=shift @ARGV; |
if ($r eq 'existence' or |
if ($rhash{$r}==0) {$restrict{$r}=1;} |
$r eq 'cvstime' or |
else {print($invocation), exit(1);} |
$r eq 'md5sum' or |
|
$r eq 'age' or |
|
$r eq 'size' or |
|
$r eq 'lines' or |
|
$r eq 'diffs') { |
|
$restrict{$r}=1; |
|
} |
|
else { |
|
print($invocation), exit(1); |
|
} |
|
} |
} |
if (%restrict) { |
if (%restrict) { |
warn('Restricting comparison to: '. |
dowarn('Restricting comparison to: '. |
join(' ',keys %restrict)."\n"); |
join(' ',keys %restrict)."\n"); |
} |
} |
|
|
|
# --------------------------------------- Define output and measure subroutines |
my %OUTPUT=( |
my %OUTPUT=( |
'existence'=>( sub {print 'existence: '.@_[0]; return;}), |
'existence'=>( sub {print 'existence: '.@_[0]; return;}), |
'md5sum'=>(sub {print 'md5sum: '.@_[0];return;}), |
'md5sum'=>(sub {print 'md5sum: '.@_[0];return;}), |
Line 206 my %MEASURE=(
|
Line 207 my %MEASURE=(
|
return ($rv1,$rv2); } ), |
return ($rv1,$rv2); } ), |
); |
); |
|
|
FLOP: foreach my $file (@files) { |
FLOOP: foreach my $file (@files) { |
my $file1; |
my $file1; |
my $file2; |
my $file2; |
if ($dirmode eq 'directories') { |
if ($dirmode eq 'directories') { |
Line 259 FLOP: foreach my $file (@files) {
|
Line 260 FLOP: foreach my $file (@files) {
|
unless (@ks) { |
unless (@ks) { |
@ks=('existence','cvstime','md5sum','age','size','lines','diffs'); |
@ks=('existence','cvstime','md5sum','age','size','lines','diffs'); |
} |
} |
FLOP2: for my $key (@ks) { |
FLOOP2: for my $key (@ks) { |
if ($key eq 'existence') { |
if ($key eq 'existence') { |
if ($existence ne 'yes:yes') { |
if ($existence ne 'yes:yes') { |
$showflag=1; |
$showflag=1; |
Line 296 FLOP: foreach my $file (@files) {
|
Line 297 FLOP: foreach my $file (@files) {
|
} |
} |
} |
} |
if ($showflag) { |
if ($showflag) { |
last FLOP2; |
last FLOOP2; |
} |
} |
} |
} |
} |
} |
Line 306 FLOP: foreach my $file (@files) {
|
Line 307 FLOP: foreach my $file (@files) {
|
@ks=('existence','md5sum','cvstime','age','size','lines','diffs'); |
@ks=('existence','md5sum','cvstime','age','size','lines','diffs'); |
} |
} |
my $showcount=length(@ks); |
my $showcount=length(@ks); |
FLOP3: for my $key (@ks) { |
FLOOP3: for my $key (@ks) { |
if ($key eq 'existence') { |
if ($key eq 'existence') { |
if ($existence ne 'yes:yes') { |
if ($existence ne 'yes:yes') { |
$showcount--; |
$showcount--; |
Line 395 FLOP: foreach my $file (@files) {
|
Line 396 FLOP: foreach my $file (@files) {
|
print &{$OUTPUT{'age'}}($age); |
print &{$OUTPUT{'age'}}($age); |
print "\t"; |
print "\t"; |
print &{$OUTPUT{'md5sum'}}($md5sum); |
print &{$OUTPUT{'md5sum'}}($md5sum); |
print "\t"; |
print "\t"; |
print &{$OUTPUT{'size'}}($size); |
print &{$OUTPUT{'size'}}($size); |
print "\t"; |
print "\t"; |
print &{$OUTPUT{'lines'}}($lines); |
print &{$OUTPUT{'lines'}}($lines); |
Line 405 FLOP: foreach my $file (@files) {
|
Line 406 FLOP: foreach my $file (@files) {
|
print "\n"; |
print "\n"; |
} |
} |
|
|
|
# ----------------------------------------------------------------- Subroutines |
|
|
sub cvstime { |
sub cvstime { |
my ($f)=@_; |
my ($f)=@_; |
my $path; my $file; |
my $path; my $file; |
Line 442 sub dowarn {
|
Line 445 sub dowarn {
|
warn($msg) unless $buildmode; |
warn($msg) unless $buildmode; |
} |
} |
|
|
|
# ----------------------------------- POD (plain old documentation, CPAN style) |
|
|
=head1 NAME |
=head1 NAME |
|
|
filecompare.pl - script used to help probe and compare file statistics |
filecompare.pl - script used to help probe and compare file statistics |