Commit 053fa863 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

This script just checks some simple things about file contents

parent fe8ca268
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use File::Find;
use Perl6::Slurp;
use Text::Diff;
my $EXCLUDE_FILES = [
qr{ \A htdocs/tests }xms,
qr{ \A htdocs/lib/adodb }xms,
qr{ \A htdocs/lib/xmldb }xms,
qr{ \A htdocs/lib/smarty }xms,
qr{ \A htdocs/lib/ddl.php }xms,
qr{ \A htdocs/lib/xmlize.php }xms,
qr{ \A htdocs/lib/kses.php }xms,
qr{ \A htdocs/lib/validateurlsyntax.php }xms,
];
my $FILE_HEADER = <<EOF;
<?php
/**
* This program is part of Mahara
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* \@package mahara
EOF
my $projectroot = qq{$FindBin::Bin/../};
find( \&process, $projectroot );
sub process {
my $filename = $_;
my $directory = $File::Find::dir;
$directory =~ s{ \A $projectroot }{}xms;
$directory =~ s{ ([^/])$ }{$1/}xms;
return unless $filename =~ m{ \.php \z }xms;
foreach my $exclude_file ( @{$EXCLUDE_FILES} ) {
return if ( ( $directory . $filename ) =~ $exclude_file );
}
my $file_data = slurp $projectroot . $directory . $filename;
# check header
if ( $FILE_HEADER ne substr ($file_data, 0, length $FILE_HEADER) ) {
my $header = substr ($file_data, 0, length $FILE_HEADER);
print $directory, $filename, " failed header check\n";
print diff \$header, \$FILE_HEADER;
}
# check footer
if ( $file_data !~ m{ \? > \n \z }xms ) {
print $directory, $filename, " failed footer check\n";
}
# check subpackage
if ( $file_data =~ m{ \@subpackage (.*?) $ }xms ) {
my $subpackage_data = $1;
unless (
$subpackage_data =~ m{ \s* ( core | form | auth | lang | tests | admin | ( artefact | notification )(?:/.+)? ) \s* }xms
) {
print $directory, $filename, " invalid \@subpackage '$subpackage_data'\n";
}
}
else {
print $directory, $filename, " missing \@author\n";
}
# check author
if ( $file_data =~ m{ \@author (.*?) $ }xms ) {
my $author_data = $1;
unless (
$author_data =~ m{ \s* Martyn \s Smith \s <martyn\@catalyst\.net\.nz> \s* }xms
or $author_data =~ m{ \s* Penny \s Leach \s <penny\@catalyst\.net\.nz> \s* }xms
or $author_data =~ m{ \s* Nigel \s McNie \s <nigel\@catalyst\.net\.nz> \s* }xms
) {
print $directory, $filename, " invalid \@author '$author_data'\n";
}
}
else {
print $directory, $filename, " missing \@author\n";
}
# check copyright
if ( $file_data !~ m{\@copyright \(C\) 2006,2007 Catalyst IT Ltd http://catalyst\.net\.nz} ) {
print $directory, $filename, " missing \@copyright (or invalid)\n";
}
}
print "\n";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment