From a5fb66040bb2f4d90d0e11a14cefb3a9ae3f82d8 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Fri, 20 Sep 2013 03:35:53 +0200 Subject: [PATCH] Start moulette_get process --- hooks/subjects.pl | 107 ++++++++++++++++++++++++++++++++++ process/files/moulette_get.pl | 91 +++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 process/files/moulette_get.pl diff --git a/hooks/subjects.pl b/hooks/subjects.pl index ef18267..79db388 100755 --- a/hooks/subjects.pl +++ b/hooks/subjects.pl @@ -163,6 +163,8 @@ sub tag_defense # TODO: check user permissions + # TODO: check presence in project.xml + # Generate questions and answer id my $defense = Defense->new(\$content); $defense->genIds(); @@ -352,7 +354,112 @@ sub tag_project sub tag_ref { + my $creation = shift; + # From here, we have: + # 1: "ref" + # 2: $id + # 3: rendu-X + # 4: $year + + my $project_id = repository_name(); + if ($_[2]) { + + # Check on ID/flavour_id + if ($_[2] =~ /^\d+$/) { + log ERROR, "ref,* tag can't take version. Tag format: ref,id,rendu,year"; + } + + $project_id .= "-" . $_[2]; + } + $project_id = lc $project_id; + $project_id =~ s/[^a-z0-9-_]/_/g; + + my $rendu; + if ($_[3]) { + $rendu = $_[3]; + } + else { + $rendu = "*"; + } + + my $year; + if ($_[4]) { + # Check on year + if ($_[4] !~ /^\d+$/) { + log ERROR, "ref,*,*,* third argument is the year. Tag format: ref,id,rendu,year"; + } + + $year = $_[4]; + } + else { + $year = LDAP::get_year; + } + + # Determine full tag + my $long_tag; + { + my $proj_id = $_[2] // ""; + $long_tag = "ref,$proj_id,$rendu,$year"; + } + + if ($creation) + { + my $newref = $ARGV[2]; + + log INFO, "Création/mise à jour de la ref..."; + + my $content = qx(git show $newref:ref/Makefile); + # Check file exists + if ($?) { + log ERROR, "Un fichier Makefile est requis pour pouvoir compiler et exécuter la ref."; + } + + log INFO, "Création de la tarball..."; + + my $archive = qx(git archive --format=tgz $newref ref/); + + # Send data to moulette + log INFO, "Attente d'un processus de compilation..."; + if (my $err = Process::Client::launch("moulette_get", { + type => "ref", + id => $project_id, + "year" => $year, + "rendu" => $rendu, + "file" => "ref_$rendu.tgz" + }, { "ref_$rendu.tgz" => $archive })) + { + if (${ $err } ne "Ok") { + log ERROR, "Erreur durant le processus de compilation : " . ${ $err }; + } + } + + if ($long_tag) + { + qx(git tag -f $long_tag); + if (! $?) { + log INFO, "Tag long créé : $long_tag."; + } + } + } + else + { + # Is the long tag existing + qx(git tag | egrep "^$long_tag\$"); + if ($?) { + log ERROR, "Tag long correspondant introuvable : $long_tag."; + } + + log USAGE, "Suppression du projet !"; + + if ($long_tag) + { + qx(git tag -d $long_tag); + if (! $?) { + log INFO, "Tag long supprimé : $long_tag."; + } + } + } } sub tag_tests diff --git a/process/files/moulette_get.pl b/process/files/moulette_get.pl new file mode 100644 index 0000000..f5d48df --- /dev/null +++ b/process/files/moulette_get.pl @@ -0,0 +1,91 @@ +#! /usr/bin/env perl + +use v5.10.1; +use strict; +use warnings; +use Pod::Usage; +use File::Temp; + +use ACU::Log; +use ACU::Process; + +my %actions = ( + "tar" => \&receive_tar, + "git" => \&receive_tar, # \&receive_git + + "tests" => \&create_testsuite, + "moulette" => \&moulette, +); + +sub receive_tar +{ + my $project_id = $args->{param}{id}; + my $year = $args->{param}{year}; + my $rendu = $args->{param}{rendu}; + my $file = $args->{param}{file}; + + if (!exists $args->{files}{$file}) { + return "No file named '$file' given". + } + + ($fh, $filename) = tempfile(SUFFIX => $file); + binmode($fh); + print $fh $args->{files}{$file}; + close $fh; + + # TODO: Call Fact for create .ff + + return "Ok" +} + +sub create_testsuite +{ + my $project_id = $args->{param}{id}; + my $year = $args->{param}{year}; + my $rendu = $args->{param}{rendu}; + my $file = $args->{param}{file}; + + ($fh, $filename) = tempfile(); + + if (!exists $args->{files}{$file}) { + return "No file named '$file' given". + } + + ($fh, $filename) = tempfile(SUFFIX => $file); + binmode($fh); + print $fh $args->{files}{$file}; + close $fh; + + # TODO: Call Fact to create testsuite + + return "Ok" +} + +sub moulette +{ + my $project_id = $args->{param}{id}; + my $year = $args->{param}{year}; + my $rendu = $args->{param}{rendu}; + my $login = $args->{param}{login}; + + # TODO: Call Fact to launch student tarball + + return "Ok" +} + + +sub process_get +{ + my ($given_args, $args) = @_; + + my $type = $args->{param}{type}; + + if (! exists $actions{$type}) { + log WARN, "Unknown type '$type'"; + return "Unknown type '$type'."; + } + + return $actions{$type}($args); +} + +Process::register("moulette_get", \&process_get);