From e0c29ad6865aa1ff88f9078c3a7d79980a89ea34 Mon Sep 17 00:00:00 2001 From: bolkun <bolkun@BDV092.slub-dresden.de> Date: Thu, 29 Apr 2021 13:50:32 +0200 Subject: [PATCH] Replaced confess with color error print and die function --- bin/slubsipbuilderbagit.pl | 92 +++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/bin/slubsipbuilderbagit.pl b/bin/slubsipbuilderbagit.pl index c411853..291d2da 100644 --- a/bin/slubsipbuilderbagit.pl +++ b/bin/slubsipbuilderbagit.pl @@ -610,43 +610,69 @@ if ($help) { pod2usage(1); } # man if ($man) { pod2usage(-exitval => 0, -verbose => 2); } # save -if (!defined $save || $save eq "") { confess("you need to specify a --save_option, available <replace> or <copy> or <move>"); } +if (!defined $save || $save eq "") { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify a --save_option, available <replace> or <copy> or <move>", "", "red"); + die(); +} # ieDirectory if (!defined $ieDirectory || $ieDirectory eq "") { confess("you need to specify an --IE_directory, which needs to be archived"); } -if (! -d $ieDirectory) { confess("you need to specify a valid --IE_directory, status: is not a directory"); } +if (! -d $ieDirectory) { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify a valid --IE_directory, status: is not a directory", "", "red"); + die(); +} # outputPath if (!defined $outputPath && ($save eq "copy" || $save eq "move")) { - confess("you need to specify an --SIP_output_path, where the SIP will be stored"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --SIP_output_path, where the SIP will be stored", "", "red"); + die(); } if (defined $outputPath && $outputPath eq "" && ($save eq "copy" || $save eq "move")) { - confess("you need to specify an --SIP_output_path, where the SIP will be stored"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --SIP_output_path, where the SIP will be stored", "", "red"); + die(); } # ppn, noppn -if (defined $ppn && defined $noppn) { confess("you can only specify either --ppn or --noppn"); } -if ((!defined $ppn && !defined $noppn) || (!defined $ppn && $noppn eq "") || (!defined $noppn && $ppn eq "")) { confess("you need to specify a PPN with --ppn or use --noppn"); } +if (defined $ppn && defined $noppn) { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you can only specify either --ppn or --noppn", "", "red"); + die(); +} +if ((!defined $ppn && !defined $noppn) || (!defined $ppn && $noppn eq "") || (!defined $noppn && $ppn eq "")) { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify a PPN with --ppn or use --noppn", "", "red"); + die(); +} #########################################################> bag-info.txt <############################################################################### # sipversion if (!defined $sipVersion || $sipVersion eq "") { - confess("you need to specify --SIP_version, current tool supports <v2020.1>"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify --SIP_version, current tool supports <v2020.1>", "", "red"); + die(); } else { - if ($sipVersion ne "v2020.1") { confess("not valid --SIP_version, current tool supports <v2020.1>"); } + if ($sipVersion ne "v2020.1") { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: not valid --SIP_version, current tool supports <v2020.1>", "", "red"); + die(); + } utf8::decode($sipVersion); push @addBagInfo, {'SLUBArchiv-sipVersion' => $sipVersion}; } # externalWorkflow if (!defined $externalWorkflow || $externalWorkflow eq "") { - confess("you need to specify external workflow"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify external workflow", "", "red"); + die(); } else { - if ($externalWorkflow !~ m#^[a-z0-9_-]+$#) { confess("you need to specify a valid --external_workflow (^[a-z0-9_-]+\$)"); } + if ($externalWorkflow !~ m#^[a-z0-9_-]+$#) { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify a valid --external_workflow (^[a-z0-9_-]+\$)", "", "red"); + die(); + } utf8::decode($externalWorkflow); push @addBagInfo, {'SLUBArchiv-externalWorkflow' => $externalWorkflow}; } # externalId if (!defined $externalId || $externalId eq "") { - confess("you need to specify external ID"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify external ID", "", "red"); + die(); } else { - if ($externalId !~ m#^[a-z0-9_-]+$#) { confess("you need to specify a valid --external_id (^[a-z0-9_-]+\$)"); } + if ($externalId !~ m#^[a-z0-9_-]+$#) { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify a valid --external_id (^[a-z0-9_-]+\$)", "", "red"); + die(); + } utf8::decode($externalId); push @addBagInfo, {'SLUBArchiv-externalId' => $externalId}; } @@ -668,16 +694,21 @@ utf8::decode($hasConservationReason); push @addBagInfo, {'SLUBArchiv-hasConservationReason' => $hasConservationReason}; # archivalValueDescription if (!defined $archivalValueDescription || $archivalValueDescription eq "") { - confess("you need to specify an --external_value_descr (reason for archiving)"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --external_value_descr (reason for archiving)", "", "red"); + die(); } else { utf8::decode($archivalValueDescription); push @addBagInfo, {'SLUBArchiv-archivalValueDescription' => $archivalValueDescription}; } # rightsVersion if (!defined $rightsVersion || $rightsVersion eq "") { - confess("you need to specify --rights_version"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify --rights_version", "", "red"); + die(); } else { - if($rightsVersion ne "1.0") { confess("invalid --rights_version, supported version <1.0>"); } + if($rightsVersion ne "1.0") { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: invalid --rights_version, supported version <1.0>", "", "red"); + die(); + } utf8::decode($rightsVersion); push @addBagInfo, {'SLUBArchiv-rightsVersion' => $rightsVersion}; } @@ -685,7 +716,8 @@ if (!defined $rightsVersion || $rightsVersion eq "") { if (@addKeyValue) { foreach my $zeile(@addKeyValue) { if($zeile !~ m#^.*:.*$#) { # : must be minimum once present - confess('wrong construct in --add_key_value="' . $zeile . '", expected --add_key_value="key:value", regexp to match is (^[^:]+:[^:]+$)'); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", 'ERROR: wrong construct in --add_key_value="' . $zeile . '", expected --add_key_value="key:value", regexp to match is (^[^:]+:[^:]+$)', "", "red"); + die(); } else { utf8::decode($zeile); my @keyvalue = split(/:/, $zeile, 2); # split on first : @@ -699,16 +731,19 @@ if (@addKeyValue) { $key eq 'SLUBArchiv-hasConservationReason' || $key eq 'SLUBArchiv-archivalValueDescription' || $key eq 'SLUBArchiv-rightsVersion'){ - confess("Duplicate key $key present at --add_key_value. Notice: $key is reserved by SLUB Dresden."); - print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: duplicate key $key present at --add_key_value. Notice: $key is reserved by SLUB Dresden.", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + die(); } if($key eq 'Bag-Count'){ - confess("$key present at --add_key_value. This key is not available due to SLUB spesification."); - print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: $key present at --add_key_value. This key is not available due to SLUB spesification.", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + die(); } if($key eq 'Bag-Group-Identifier'){ - confess("$key present at --add_key_value. This key is not available due to SLUB spesification."); - print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: $key present at --add_key_value. This key is not available due to SLUB spesification.", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + die(); } push @addBagInfo, {$key => $value}; } @@ -717,13 +752,20 @@ if (@addKeyValue) { ########################################################################################################################################################## # rightsFilePath -if (!defined $rightsFilePath || $rightsFilePath eq "") { confess("you need to specify --rights_xml file, which needs to be added"); } -if (! -f $rightsFilePath) { confess("you need to specify --rights_xml file, status: is not a file"); } +if (!defined $rightsFilePath || $rightsFilePath eq "") { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify --rights_xml file, which needs to be added", "", "red"); + die(); +} +if (! -f $rightsFilePath) { + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify --rights_xml file, status: is not a file", "", "red"); + die(); +} # addMetaFile if (@addMetaFile) { foreach my $file(@addMetaFile) { if(! -f $file) { - confess("file $file at --add_meta_file, is not a file or could not be found"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: file $file at --add_meta_file, is not a file or could not be found", "", "red"); + die(); } } } -- GitLab