[LON-CAPA-cvs] cvs: modules /sharrison/fomtools fomfix.pl

harris41 lon-capa-cvs@mail.lon-capa.org
Sat, 27 Jul 2002 21:40:54 -0000


harris41		Sat Jul 27 17:40:54 2002 EDT

  Added files:                 
    /modules/sharrison/fomtools	fomfix.pl 
  Log:
  script for fixing FOM files to a default attribution policy
  
  

Index: modules/sharrison/fomtools/fomfix.pl
+++ modules/sharrison/fomtools/fomfix.pl
#!/usr/bin/perl

=pod

=head1 NAME

B<fomfix.pl> - fix FAQ-o-matic files

=head1 SYNOPSIS

Should only run as user=apache on the help.lon-capa.org server.

perl fomfix.pl

=head1 DESCRIPTION

Among other things, set default attribution mode to hidden.

This script might even be customized in the future to
have a spellchecker.

=head1 AUTHOR

Scott Harrison

=cut

# Note that the files should be owned by apache:apache
# Therefore, to be safe, this script should run as user apache.

my $apacheid=getpwnam('apache');
if ($apacheid!=$<) {
    die("**** ERROR **** This script needs to run as user='apache'\n");
}

# Note: /home/SOMEUSER is bad location for FOM files, but will fix this later.
    my $itemsdir='/home/albertel/fom-serve/item';
#    my $itemsdir='testdir';
    my $tmpdir='/tmp/fomfix';

opendir(DIR,$itemsdir) or die("can't open $itemsdir");
my @fomfiles=grep { !/^\./ } readdir(DIR);
closedir(DIR);

system("install -d $tmpdir") and die("can't make $tmpdir");
foreach my $file (@fomfiles) {
    `cp -v $itemsdir/$file $tmpdir/$file`;
    my $newstring='';
    open(IN,"<$tmpdir/$file");
    my $oldline='';
    while(my $line=<IN>) {
	if ($line=~/^LastModifiedSecs\:\s/) {
	    if ($oldline=~/^Author\-Set\:\s/) {
		print "File: $file being adjusted for attributions.\n";
		$newstring.="HideAttributions: 1\n";
		$newstring.=$line;
	    }
	    else {
		$newstring.=$line;
	    }
	}
	else {
		$newstring.=$line;
	}
	$oldline=$line;
    }
    close(IN);
    open(OUT,">$tmpdir/$file");
    print(OUT <<END);
$newstring
END
    close(OUT);
    system("diff $tmpdir/$file $itemsdir/$file | grep -q HideAttributions") or
	`cp -v $tmpdir/$file $itemsdir/$file`;
}