Skip to content
Snippets Groups Projects
Commit 4c79734a authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- fixed validation using algorithm explicitely

- added different output formats
parent 5bf7338d
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package SLUB::LZA::TA::Command::permanent; ...@@ -2,6 +2,7 @@ package SLUB::LZA::TA::Command::permanent;
use SLUB::LZA::TA -command; use SLUB::LZA::TA -command;
use v5.36; use v5.36;
use SLUB::LZA::TA::Archivematica::Elasticsearch; use SLUB::LZA::TA::Archivematica::Elasticsearch;
use SLUB::LZA::TA::Output;
use Archive::BagIt; use Archive::BagIt;
use File::Find; use File::Find;
use namespace::autoclean; use namespace::autoclean;
...@@ -22,7 +23,15 @@ sub description { ...@@ -22,7 +23,15 @@ sub description {
sub opt_spec { sub opt_spec {
my @global_opts= SLUB::LZA::TA::common_global_opt_spec(); my @global_opts= SLUB::LZA::TA::common_global_opt_spec();
my @local_opts = ( my @local_opts = (
[] [ 'output-format' => hidden => {
one_of => [
[ 'output-as-csv|C' => 'prints output as Comma Separated Values (CSV)' ],
[ 'output-as-raw|R' => 'print raw hash output of elasticsearch response' ],
[ 'output-as-rsv|r' => 'prints output as Raw Strings Values (RSV)' ],
[ 'output-as-asciidoc|a' => 'prints output as human readable AsciiDoc (default)' ],
],
}
],
); );
return (@global_opts, [], @local_opts); return (@global_opts, [], @local_opts);
} }
...@@ -31,30 +40,50 @@ sub validate_args { ...@@ -31,30 +40,50 @@ sub validate_args {
SLUB::LZA::TA::common_global_validate($self, $opt, $args); SLUB::LZA::TA::common_global_validate($self, $opt, $args);
# no args allowed but options! # no args allowed but options!
$self->usage_error("No args allowed") if @$args; $self->usage_error("No args allowed") if @$args;
if (!exists $opt->{output_format}) { $opt->{output_format} = 'output_as_asciidoc';}
return 1; return 1;
} }
sub execute { sub execute {
my ($self, $opt, $args) = @_; my ($self, $opt, $args) = @_;
use Data::Printer; p($opt); p(%SLUB::LZA::TA::config);
my %result;
my @candidates; my @candidates;
my $wanted = sub { my $wanted = sub {
my ($dev,$ino,$mode,$nlink,$uid,$gid); my ($dev, $ino, $mode, $nlink, $uid, $gid);
(($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && and (-d _)
-f _ && and (-f "$_/bagit.txt")
/^bag-info\.txt\z/s && and ($File::Find::prune = 1)
($File::Find::prune = 1) and push @candidates, $File::Find::name;
&& push @candidates, $File::find::dir;
}; };
File::Find::find({wanted => $wanted}, @{ $SLUB::LZA::TA::config{permanent_volume} } ); File::Find::find(
foreach my $candidate (@candidates) { {wanted => $wanted},
@{ $SLUB::LZA::TA::config{permanent_volume} }
);
my @results = map {
my $candidate = $_;
my $bag = Archive::BagIt->new($candidate); my $bag = Archive::BagIt->new($candidate);
# explicite SHA loading, because
# Archivematica only use SHA512, but have version 0.97
$bag->use_plugins('Archive::BagIt::Plugin::Algorithm::SHA512');
my $is_valid = $bag->verify_bag(); my $is_valid = $bag->verify_bag();
$result{$candidate} = $is_valid; my $line;
say "$candidate is " . ($is_valid ? "valid" : "invalid"); $line->{'AIP storage path'} = $candidate;
$line->{'bagit validation result'} = ($is_valid ? "valid" : "invalid");
$line;
} (sort @candidates);
my @headers = sort keys %{$results[0]};
if ($opt->{output_format} eq 'output_as_csv') {
SLUB::LZA::TA::Output::CSV::print_results(\@headers, \@results);
} elsif ($opt->{output_format} eq 'output_as_rsv') {
SLUB::LZA::TA::Output::RSV::print_results(\@headers, \@results);
} elsif ($opt->{output_format} eq 'output_as_raw') {
SLUB::LZA::TA::Output::Raw::print_results(\@results);
} else {
SLUB::LZA::TA::Output::Asciidoc::print_results(\@headers, \@results);
} }
return 1; return 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment