Start check submission script

This commit is contained in:
Némunaire 2013-12-11 18:10:39 +01:00
parent 4d1918a530
commit bc877802cc

80
check.pl Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env perl
use v5.10.1;
use strict;
use warnings;
use DBI;
use Data::Dumper;
# First, read PHP configuration to extract some settings
my $profile;
my $submission_dir;
open my $conf, "<", "onyx/config/root.xml";
for my $p (<$conf>)
{
if ($p =~ /<(?:option|var) name="(.*)">(.*)<\/(?:option|var)>/)
{
$profile = $2 if ($1 eq "profile");
$submission_dir = $2 if ($1 eq "submission_dir");
}
}
close $conf;
die("No DB profile found") if ! $profile;
die("submission_dir is not a directory") if ! $submission_dir || ! -d $submission_dir;
# Read db settings
my %db_settings;
open my $dbprof, "<", "onyx/db/$profile.profile.php";
while (<$dbprof>)
{
if (/\$___profile\[['"](.+)['"]\] = ['"](.+)['"]/)
{
$db_settings{$1} = $2;
}
}
close $dbprof;
my $dbh;
# List all files to treat
opendir(my $dh, $submission_dir) || die "Can't opendir submission_dir: $!";
for my $f (readdir $dh)
{
if ($f =~ /^([0-9]+)-([0-9]+)-([0-9]+)$/)
{
my $team = $1;
my $theme = $2;
my $exercice = $3;
open my $fh, "<", "$submission_dir/$f";
my $solution = <$fh>;
close $fh;
$dbh = DBI->connect("DBI:mysql:database=$db_settings{db};host=$db_settings{host};port=3306",
$db_settings{user}, $db_settings{pass},
{'RaiseError' => 1, 'PrintError' => 1})
or die $DBI::errstr if !$dbh;
my $sth = query($dbh, "SELECT format, value FROM exercice_keys WHERE id_exercice = ".int($exercice));
while (my $row = get_row($sth))
{
say Dumper($row);
}
}
}
closedir $dh;
$dbh->disconnect() if $dbh;
sub query
{
my $sth = $_[0]->prepare($_[1]);
$sth->execute();
die($_[0]->errstr) if (!$sth);
return $sth;
}