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

- added CLI options for output-format, allows output as RSV, CSV, raw and AsciiDoc

- changed short option for '--complete' to '-c' to avoid conflicts
- added new option '--with-ldp' for additional LDP specific reports
parent 4dd7aceb
No related branches found
No related tags found
No related merge requests found
......@@ -51,10 +51,22 @@ sub opt_spec {
[ 'weekly|W' => 'report based on last week'],
[ 'monthly|m' => 'report based on last month (default)' ],
[ 'yearly|y' => 'report based on last year' ],
[ 'complete|C'=> 'report based on all AIPs'],
[ 'complete|c'=> 'report based on all AIPs'],
],
},
],
[],
[ 'output-format' => hidden => {
one_of => [
[ 'output-as-csv|C' => 'prints output as Comma Separated Values (CSV)' ],
[ 'output-as-raw|R' => 'print raw hash output' ],
[ 'output-as-rsv|r' => 'prints output as Raw Strings Values (RSV)' ],
[ 'output-as-asciidoc|a' => 'prints output as AsciiDoc [default]' ],
],
}
],
[],
[ 'with-ldp|l' => 'report with LDP'],
[ 'workflow|w=s' => 'LZA internal workflow name (optional)'],
[],
[ 'help|h', 'print usage message and exit', { shortcircuit => 1 } ],
......@@ -85,6 +97,9 @@ sub validate_args {
$from_year=2015; $from_month=1; $from_day=1;
$to_year=$cyear; $to_month=$cmonth; $to_day=$cday;
}
if (!exists $opt->{output_format}) {
$opt->{output_format} = 'output_as_asciidoc';
}
printf STDERR "reporting for period %04u-%02u-%02u … %04u-%02u-%02u\n", $from_year, $from_month, $from_day, $to_year, $to_month, $to_day;
my $from_epoch = Date_to_Time($from_year, $from_month, $from_day, 0, 0, 0);
my $to_epoch = Date_to_Time($to_year, $to_month, $to_day, 0, 0, 0);
......@@ -181,7 +196,10 @@ sub execute {
$results{package} = __PACKAGE__;
$results{from} = $opt->{creationdate_epochs}->{from_string};
$results{to} = $opt->{creationdate_epochs}->{to_string};
my @ldp_projects= get_ldp_projects(@_);
my @ldp_projects;
if ($opt->{with_ldp}) {
@ldp_projects = get_ldp_projects(@_);
}
foreach my $aip_state (qw(total new updated)) {
my %newhash = %{$opt};
if ($aip_state eq 'new') {$newhash{only_new} = 1;}
......@@ -200,7 +218,8 @@ sub execute {
$results{flavour}->{size}->{$aip_state}->{$ldp_funder} = $res->{aggregations}->{total_aip_size}->{value};
$results{flavour}->{files}->{$aip_state}->{$ldp_funder} = $res->{aggregations}->{total_file_count}->{value};
}
foreach my $ldp_project (@ldp_projects) {
foreach my $ldp_project (@ldp_projects) { # only if @ldp_projects have size > 1
my %newhash = %{$opt};
if ($aip_state eq 'new') {$newhash{only_new} = 1;}
elsif ($aip_state eq 'updated') {$newhash{only_updated} = 1;}
......@@ -210,10 +229,17 @@ sub execute {
$results{ldp_project}->{$ldp_project}->{flavour}->{size}->{$aip_state} = $res->{aggregations}->{total_aip_size}->{value};
$results{ldp_project}->{$ldp_project}->{flavour}->{files}->{$aip_state} = $res->{aggregations}->{total_file_count}->{value};
}
}
#print_humanreadable_report(\%results);
if ($opt->{output_format} eq 'output_as_asciidoc') {
print_humanreadable_report(\%results);
} else {
my ($headers, $table) = prepare_for_table(\%results, \@ldp_projects);
SLUB::LZA::TA::Output::CSV::print_results($headers, $table);
if ($opt->{output_format} eq 'output_as_rsv') {SLUB::LZA::TA::Output::RSV::print_results($headers, $table);}
elsif ($opt->{output_format} eq 'output_as_csv') {SLUB::LZA::TA::Output::CSV::print_results($headers, $table);}
elsif ($opt->{output_format} eq 'output_as_raw') { SLUB::LZA::TA::Output::Raw::print_results(\%results);}
}
say STDERR "report is already sent to STDOUT.";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment