Archived
1
0
This repository has been archived on 2021-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
ACU/process/files/intradata_get.pl
Mercier Pierre-Olivier 51e366b156 Fix args order
2013-09-12 13:36:43 +02:00

96 lines
1.8 KiB
Perl

#! /usr/bin/env perl
use v5.10.1;
use strict;
use warnings;
use Pod::Usage;
use lib "../../";
use ACU::Log;
use ACU::LDAP;
use ACU::Process;
our $basedir = "/intradata";
my %actions = (
"project" => {
"create" => \&update_project,
"update" => \&update_project,
"delete" => \&delete_project,
}
);
sub create_tree($$)
{
my $year = shift;
my $project_id = shift;
if (! -d "$basedir/$year/") {
log ERROR, "No directory for year $year. Ask a root to create it.";
return "No directory for year $year. Ask a root to create it.";
}
if (! -e "$basedir/$year/$project_id/") {
mkdir "$basedir/$year/$project_id/";
}
return 0;
}
sub update_project
{
my $args = shift;
my $project_id = $args->{param}{id};
my $year = $args->{param}{year} // LDAP::get_year;
if (! $project_id) {
log ERROR, "No project_id given.";
return "No project_id given";
}
my $butler;
if (exists $args->{files}{"butler.xml"}) {
$butler = $args->{files}{"butler.xml"};
}
if (! $butler) {
log ERROR, "Invalid butler.xml received!";
return "Invalid butler.xml received!";
}
log INFO, "Update $year/$project_id/butler.xml";
return $_ if (! create_tree($year, $project_id));
open my $out, ">", "$year/$project_id/butler.xml";
print $out $butler;
close $out;
return "Ok";
}
sub delete_project
{
log WARN, "delete_project: not implemented."
}
sub process_get
{
my ($given_args, $args) = @_;
my $type = $args->{param}{type};
my $action = $args->{param}{action} // "update";
if (! exists $actions{$type}{$action}) {
log WARN, "Unknown action '$action' for $type.";
return "Unknown action '$action' for $type.";
}
return $actions{$type}{$action}($args);
}
Process::register("intradata_get", \&process_get);