Last moulette_get
This commit is contained in:
parent
e009942a7c
commit
784c7cfb55
2 changed files with 76 additions and 65 deletions
|
@ -42,7 +42,7 @@ sub create_tree($$)
|
|||
croak "No directory for year $year. Ask a root to create it." if (! -d "$basedir/$year/");
|
||||
|
||||
if (! -e "$basedir/$year/$project_id/") {
|
||||
mkdir "$basedir/$year/$project_id/";
|
||||
mkdir "$basedir/$year/$project_id/" or croak $!;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ sub grades_generate
|
|||
croak "No project_id given." if (! $project_id);
|
||||
|
||||
if (! -e "$basedir/$year/$project_id/grades/") {
|
||||
mkdir "$basedir/$year/$project_id/grades/";
|
||||
mkdir "$basedir/$year/$project_id/grades/" or croak $!;
|
||||
}
|
||||
|
||||
log DEBUG, "Generate list of students";
|
||||
|
@ -149,10 +149,10 @@ sub grades_new_bonus
|
|||
croak "No project_id given" if (! $project_id);
|
||||
|
||||
if (! -e "$basedir/$year/$project_id/traces/") {
|
||||
mkdir "$basedir/$year/$project_id/traces/";
|
||||
mkdir "$basedir/$year/$project_id/traces/" or croak $!;
|
||||
}
|
||||
if (! -e "$basedir/$year/$project_id/traces/bonus/") {
|
||||
mkdir "$basedir/$year/$project_id/traces/bonus/";
|
||||
mkdir "$basedir/$year/$project_id/traces/bonus/" or croak $!;
|
||||
}
|
||||
|
||||
for my $kfile (keys %{ $args->{files} })
|
||||
|
@ -251,19 +251,19 @@ sub update_defense
|
|||
log INFO, "Update $year/$project_id/defenses/$defense_id.xml";
|
||||
|
||||
if (! -e "$basedir/$year/$project_id/defenses/") {
|
||||
mkdir "$basedir/$year/$project_id/defenses/";
|
||||
mkdir "$basedir/$year/$project_id/defenses/" or croak $!;
|
||||
}
|
||||
if (! -e "$basedir/$year/$project_id/traces/") {
|
||||
mkdir "$basedir/$year/$project_id/traces/";
|
||||
mkdir "$basedir/$year/$project_id/traces/" or croak $!;
|
||||
}
|
||||
if (! -e "$basedir/$year/$project_id/traces/defense_$defense_id/") {
|
||||
mkdir "$basedir/$year/$project_id/traces/defense_$defense_id/";
|
||||
mkdir "$basedir/$year/$project_id/traces/defense_$defense_id/" or croak $!;
|
||||
my ($login, $pass, $uid, $gid) = getpwnam("www-data");
|
||||
chown $uid, $gid, "$basedir/$year/$project_id/traces/defense_$defense_id/";
|
||||
chmod 0775, "$basedir/$year/$project_id/traces/defense_$defense_id/";
|
||||
chown $uid, $gid, "$basedir/$year/$project_id/traces/defense_$defense_id/" or croak $!;
|
||||
chmod 0775, "$basedir/$year/$project_id/traces/defense_$defense_id/" or croak $!;
|
||||
}
|
||||
|
||||
open my $out, ">", "$basedir/$year/$project_id/defenses/$defense_id.xml";
|
||||
open my $out, ">", "$basedir/$year/$project_id/defenses/$defense_id.xml" or croak $!;
|
||||
print $out $defense;
|
||||
close $out;
|
||||
|
||||
|
@ -322,11 +322,11 @@ sub update_trace
|
|||
log INFO, "Update $year/$project_id/traces/$rendu_id/$login.xml";
|
||||
|
||||
if (! -e "$basedir/$year/$project_id/traces/") {
|
||||
mkdir "$basedir/$year/$project_id/traces/";
|
||||
mkdir "$basedir/$year/$project_id/traces/" or croak $!;
|
||||
}
|
||||
if (! -e "$basedir/$year/$project_id/traces/$rendu_id/") {
|
||||
mkdir "$basedir/$year/$project_id/traces/$rendu_id/";
|
||||
chmod 0755, "$basedir/$year/$project_id/traces/$rendu_id/";
|
||||
mkdir "$basedir/$year/$project_id/traces/$rendu_id/" or croak $!;
|
||||
chmod 0755, "$basedir/$year/$project_id/traces/$rendu_id/" or croak $!;
|
||||
}
|
||||
|
||||
open my $out, ">", "$basedir/$year/$project_id/traces/$rendu_id/$login.xml" or croak("Unable to write to $rendu_id/$login.xml");
|
||||
|
|
|
@ -4,6 +4,7 @@ use v5.10.1;
|
|||
use strict;
|
||||
use warnings;
|
||||
use threads;
|
||||
use threads::shared;
|
||||
use Carp;
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
|
@ -22,8 +23,7 @@ my %actions = (
|
|||
"moulette" => \&moulette,
|
||||
);
|
||||
|
||||
my $fm = new Sys::Gamin;
|
||||
my %project_paths;
|
||||
my %monitored_dir = ();
|
||||
|
||||
sub jail_exec
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ sub prepare_dir
|
|||
my $project_id = shift;
|
||||
my $rendu = shift;
|
||||
|
||||
my @dirs = ("/data/work/$year-$project_id-$rendu/", "/data/output/$year-$project_id-$rendu/");
|
||||
my @dirs = ("/data/work/$year-$project_id-$rendu/", "/data/output/$year-$project_id-$rendu/", "/data/files/$year-$project_id-$rendu/");
|
||||
|
||||
for my $dir (@dirs)
|
||||
{
|
||||
|
@ -82,11 +82,13 @@ sub receive_ref
|
|||
jail_exec("gmake -C $tempdir/ref/ fact");
|
||||
croak "An error occurs while making the testsuite" if ($?);
|
||||
|
||||
my $destdir = ( prepare_dir($year, $project_id, $rendu) )[0];
|
||||
my $destdir = ( prepare_dir($year, $project_id, $rendu) )[2];
|
||||
copy("$tempdir/ref/ref.ff", "$destdir/ref.ff") or croak "An error occurs while coping ref.ff: $!";
|
||||
|
||||
# Clean
|
||||
remove_tree($tempdir);
|
||||
|
||||
run_moulette($project_id, $year, $rendu);
|
||||
}
|
||||
|
||||
sub receive_std
|
||||
|
@ -107,7 +109,7 @@ sub receive_std
|
|||
|
||||
croak "An error occurs while extracting the tarball" if ($?);
|
||||
|
||||
my $destdir = ( prepare_dir($year, $project_id, $rendu) )[0];
|
||||
my $destdir = ( prepare_dir($year, $project_id, $rendu) )[2];
|
||||
fact_exec("package create '$tempdir' '$destdir/$login.ff'", $destdir);
|
||||
croak "Cannot create $login.ff" if ($?);
|
||||
chmod 0666, "$destdir/$login.ff";
|
||||
|
@ -139,7 +141,7 @@ sub create_testsuite
|
|||
jail_exec("gmake -C $tempdir/tests/");
|
||||
croak "An error occurs while making the testsuite" if ($?);
|
||||
|
||||
my $destdir = ( prepare_dir($year, $project_id, $rendu) )[0];
|
||||
my $destdir = ( prepare_dir($year, $project_id, $rendu) )[2];
|
||||
copy("$tempdir/tests/tests.ff", "$destdir/tests.ff") or croak "An error occurs while coping the testsuite: $!";
|
||||
copy("$tempdir/tests/test.ft", "$destdir/test.ft") or croak "An error occurs while coping test.ft: $!";
|
||||
chmod 0660, "$destdir/tests.ff";
|
||||
|
@ -158,17 +160,15 @@ sub run_moulette
|
|||
my $rendu = shift;
|
||||
my @logins = @_;
|
||||
|
||||
#TODO: find the right test dir, '' is most generic one
|
||||
my $testdir = ( prepare_dir($year, $project_id, "") )[0];
|
||||
my ($submitdir, $outputdir) = prepare_dir($year, $project_id, $rendu);
|
||||
my ($workdir, $outputdir, $filesdir) = prepare_dir($year, $project_id, $rendu);
|
||||
|
||||
if ($#logins == -1)
|
||||
{
|
||||
# Get all submissions
|
||||
opendir(my $dh, $submitdir) or die "Can't list files in $submitdir: $!";
|
||||
opendir(my $dh, $filesdir) or die "Can't list files in $filesdir: $!";
|
||||
while (readdir($dh))
|
||||
{
|
||||
if (/([a-zA-Z0-9_-]+).ff$/ && -f "$submitdir/$_" && ! /^tests\.ff$/) {
|
||||
if (/([a-zA-Z0-9_-]+).ff$/ && -f "$filesdir/$_" && ! /^tests\.ff$/) {
|
||||
push @logins, $1;
|
||||
}
|
||||
}
|
||||
|
@ -178,25 +178,19 @@ sub run_moulette
|
|||
for my $login (@logins)
|
||||
{
|
||||
my $fhin;
|
||||
if (-f "$testdir/$login.ft") {
|
||||
open $fhin, "<", "$testdir/$login.ft" or croak "Unable to open $testdir/$login.ft: $!";
|
||||
} elsif (-f "$testdir/test.ft") {
|
||||
open $fhin, "<", "$testdir/test.ft" or croak "Unable to open $testdir/test.ft: $!";
|
||||
}
|
||||
#TODO: remove this
|
||||
elsif (-f "$submit/test.ft") {
|
||||
open $fhin, "<", "$testdir/test.ft" or croak "Unable to open $testdir/test.ft: $!";
|
||||
if (-f "$filesdir/test.ft") {
|
||||
open $fhin, "<", "$filesdir/test.ft" or croak "Unable to open $filesdir/test.ft: $!";
|
||||
}
|
||||
|
||||
if ($fhin)
|
||||
{
|
||||
open my $fhout, ">", "$submitdir/$login.ft" or croak "Unable to update $submitdir/$login.ft file: $!";
|
||||
open my $fhout, ">", "$workdir/$login.ft" or croak "Unable to update $workdir/$login.ft file: $!";
|
||||
while (<$fhin>)
|
||||
{
|
||||
$_ =~ s/#LOGIN_X/$login/g;
|
||||
$_ =~ s%#GLOBAL%/data/global/%g;
|
||||
$_ =~ s/#PROJECT/$testdir/g;
|
||||
$_ =~ s/#SUBMIT/$submitdir/g;
|
||||
$_ =~ s/#PROJECT/$filesdir/g;
|
||||
$_ =~ s/#SUBMIT/$workdir/g;
|
||||
$_ =~ s/#OUTPUT/$outputdir/g;
|
||||
print $fhout $_;
|
||||
}
|
||||
|
@ -204,20 +198,19 @@ sub run_moulette
|
|||
close $fhout;
|
||||
}
|
||||
|
||||
croak "Unable to find a relevant $login.ft, abort moulette start." if (! -f "$submitdir/$login.ft");
|
||||
copy("$filesdir/$login.ff", "$workdir/$login.ff") or croak "Cannont copy $login.ff";
|
||||
|
||||
log WARN, "There is no ref for $project_id $rendu" if (! -f "$testdir/ref.ff");
|
||||
log WARN, "There is no $login.ff for $project_id $rendu" if (! -f "$submitdir/$login.ff");
|
||||
croak "Unable to find a relevant $login.ft, abort moulette start." if (! -f "$workdir/$login.ft");
|
||||
|
||||
# Monitor the trace creation
|
||||
if (! grep { $outputdir } %project_paths)
|
||||
{
|
||||
$project_paths{$outputdir} = { "id" => $project_id, "year" => $year, "rendu" => $rendu };
|
||||
$fm->monitor($outputdir);
|
||||
}
|
||||
log WARN, "There is no ref for $project_id $rendu" if (! -f "$filesdir/ref.ff");
|
||||
log WARN, "There is no $login.ff for $project_id $rendu" if (! -f "$workdir/$login.ff");
|
||||
|
||||
log INFO, "$submitdir/$login append to Fact manager";
|
||||
fact_exec("system manager $submitdir/$login.ft", $submitdir);
|
||||
unlink "$outputdir/$login.xml" if ( -f "$outputdir/$login.xml");
|
||||
|
||||
monitor_dir($outputdir, $project_id, $year, $rendu);
|
||||
|
||||
log INFO, "$workdir/$login.ft append to Fact manager";
|
||||
fact_exec("system manager $workdir/$login.ft", $workdir);
|
||||
|
||||
log ERROR, "An error occurs while starting tests for $login on $year-$project_id-$rendu" if ($?);
|
||||
}
|
||||
|
@ -252,7 +245,9 @@ sub trace_send
|
|||
my $path = shift;
|
||||
my $filename = shift;
|
||||
my $login = shift;
|
||||
my %infos = %{ $project_paths{ $path } };
|
||||
my $id = shift;
|
||||
my $year = shift;
|
||||
my $rendu = shift;
|
||||
|
||||
return if (! -f "$path/$filename");
|
||||
|
||||
|
@ -268,9 +263,9 @@ sub trace_send
|
|||
"intradata_get",
|
||||
{ "type" => "trace",
|
||||
"action" => "update",
|
||||
"id" => $infos{id},
|
||||
"year" => $infos{year},
|
||||
"rendu" => $infos{rendu},
|
||||
"id" => $id,
|
||||
"year" => $year,
|
||||
"rendu" => $rendu,
|
||||
"login" => $login },
|
||||
{ "$login.xml" => $file_content },
|
||||
1
|
||||
|
@ -280,25 +275,42 @@ sub trace_send
|
|||
unlink "$path/$filename";
|
||||
}
|
||||
|
||||
sub monitor_traces
|
||||
{
|
||||
my $event = shift;
|
||||
|
||||
log DEBUG, "Pathname: ".$event->filename." Event: ".$event->type." Where: ".$fm->which($event);
|
||||
|
||||
if (($event->type eq "create" || $event->type eq "change" || $event->type eq "exist") &&
|
||||
$event->filename =~ /([^\/\\]+)\.xml$/ &&
|
||||
grep { $fm->which($event) } %project_paths)
|
||||
{
|
||||
trace_send($fm->which($event), $event->filename, $1);
|
||||
}
|
||||
}
|
||||
|
||||
sub monitor_start
|
||||
{
|
||||
my $dir = shift;
|
||||
my $id = shift;
|
||||
my $year = shift;
|
||||
my $rendu = shift;
|
||||
my $fm = new Sys::Gamin;
|
||||
|
||||
log INFO, "Monitoring $dir";
|
||||
$fm->monitor($dir);
|
||||
while (1) {
|
||||
my $event=$fm->next_event;
|
||||
if (($event->type eq "create" || $event->type eq "change" || $event->type eq "exist") &&
|
||||
$event->filename =~ /([^\/\\]+)\.xml$/ ) {
|
||||
my $login = $event->filename;
|
||||
$login =~ s/\.xml$//;
|
||||
trace_send($dir, $event->filename, $login, $id, $year, $rendu);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
monitor_traces( $fm->next_event ) while (1);
|
||||
}
|
||||
|
||||
sub monitor_dir
|
||||
{
|
||||
my $dir = shift;
|
||||
my $id = shift;
|
||||
my $year = shift;
|
||||
my $rendu = shift;
|
||||
|
||||
return if (exists ($monitored_dir{$dir}));
|
||||
|
||||
$monitored_dir{$dir} = threads->create(\&monitor_start, $dir, $id, $year, $rendu);
|
||||
}
|
||||
|
||||
sub process_get
|
||||
{
|
||||
my ($given_args, $args) = @_;
|
||||
|
@ -321,5 +333,4 @@ sub process_get
|
|||
return "Ok";
|
||||
}
|
||||
|
||||
threads->create('monitor_start');
|
||||
Process::register("moulette_get", \&process_get);
|
||||
|
|
Reference in a new issue