Skip to content
Snippets Groups Projects
Commit e0c29ad6 authored by bolkun's avatar bolkun
Browse files

Replaced confess with color error print and die function

parent 2b214903
No related branches found
No related tags found
1 merge request!5Feature error coloring
...@@ -610,43 +610,69 @@ if ($help) { pod2usage(1); } ...@@ -610,43 +610,69 @@ if ($help) { pod2usage(1); }
# man # man
if ($man) { pod2usage(-exitval => 0, -verbose => 2); } if ($man) { pod2usage(-exitval => 0, -verbose => 2); }
# save # 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 # ieDirectory
if (!defined $ieDirectory || $ieDirectory eq "") { confess("you need to specify an --IE_directory, which needs to be archived"); } 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 # outputPath
if (!defined $outputPath && ($save eq "copy" || $save eq "move")) { 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")) { 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 # ppn, noppn
if (defined $ppn && defined $noppn) { confess("you can only specify either --ppn or --noppn"); } if (defined $ppn && defined $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"); } 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 <############################################################################### #########################################################> bag-info.txt <###############################################################################
# sipversion # sipversion
if (!defined $sipVersion || $sipVersion eq "") { 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 { } 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); utf8::decode($sipVersion);
push @addBagInfo, {'SLUBArchiv-sipVersion' => $sipVersion}; push @addBagInfo, {'SLUBArchiv-sipVersion' => $sipVersion};
} }
# externalWorkflow # externalWorkflow
if (!defined $externalWorkflow || $externalWorkflow eq "") { 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 { } 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); utf8::decode($externalWorkflow);
push @addBagInfo, {'SLUBArchiv-externalWorkflow' => $externalWorkflow}; push @addBagInfo, {'SLUBArchiv-externalWorkflow' => $externalWorkflow};
} }
# externalId # externalId
if (!defined $externalId || $externalId eq "") { 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 { } 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); utf8::decode($externalId);
push @addBagInfo, {'SLUBArchiv-externalId' => $externalId}; push @addBagInfo, {'SLUBArchiv-externalId' => $externalId};
} }
...@@ -668,16 +694,21 @@ utf8::decode($hasConservationReason); ...@@ -668,16 +694,21 @@ utf8::decode($hasConservationReason);
push @addBagInfo, {'SLUBArchiv-hasConservationReason' => $hasConservationReason}; push @addBagInfo, {'SLUBArchiv-hasConservationReason' => $hasConservationReason};
# archivalValueDescription # archivalValueDescription
if (!defined $archivalValueDescription || $archivalValueDescription eq "") { 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 { } else {
utf8::decode($archivalValueDescription); utf8::decode($archivalValueDescription);
push @addBagInfo, {'SLUBArchiv-archivalValueDescription' => $archivalValueDescription}; push @addBagInfo, {'SLUBArchiv-archivalValueDescription' => $archivalValueDescription};
} }
# rightsVersion # rightsVersion
if (!defined $rightsVersion || $rightsVersion eq "") { 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 { } 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); utf8::decode($rightsVersion);
push @addBagInfo, {'SLUBArchiv-rightsVersion' => $rightsVersion}; push @addBagInfo, {'SLUBArchiv-rightsVersion' => $rightsVersion};
} }
...@@ -685,7 +716,8 @@ if (!defined $rightsVersion || $rightsVersion eq "") { ...@@ -685,7 +716,8 @@ if (!defined $rightsVersion || $rightsVersion eq "") {
if (@addKeyValue) { if (@addKeyValue) {
foreach my $zeile(@addKeyValue) { foreach my $zeile(@addKeyValue) {
if($zeile !~ m#^.*:.*$#) { # : must be minimum once present 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 { } else {
utf8::decode($zeile); utf8::decode($zeile);
my @keyvalue = split(/:/, $zeile, 2); # split on first : my @keyvalue = split(/:/, $zeile, 2); # split on first :
...@@ -699,16 +731,19 @@ if (@addKeyValue) { ...@@ -699,16 +731,19 @@ if (@addKeyValue) {
$key eq 'SLUBArchiv-hasConservationReason' || $key eq 'SLUBArchiv-hasConservationReason' ||
$key eq 'SLUBArchiv-archivalValueDescription' || $key eq 'SLUBArchiv-archivalValueDescription' ||
$key eq 'SLUBArchiv-rightsVersion'){ $key eq 'SLUBArchiv-rightsVersion'){
confess("Duplicate key $key present at --add_key_value. Notice: $key is reserved by SLUB Dresden."); SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: duplicate key $key present at --add_key_value. Notice: $key is reserved by SLUB Dresden.", "", "red");
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("", "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'){ if($key eq 'Bag-Count'){
confess("$key present at --add_key_value. This key is not available due to SLUB spesification."); SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: $key present at --add_key_value. This key is not available due to SLUB spesification.", "", "red");
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("", "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'){ if($key eq 'Bag-Group-Identifier'){
confess("$key present at --add_key_value. This key is not available due to SLUB spesification."); SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: $key present at --add_key_value. This key is not available due to SLUB spesification.", "", "red");
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("", "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}; push @addBagInfo, {$key => $value};
} }
...@@ -717,13 +752,20 @@ if (@addKeyValue) { ...@@ -717,13 +752,20 @@ if (@addKeyValue) {
########################################################################################################################################################## ##########################################################################################################################################################
# rightsFilePath # rightsFilePath
if (!defined $rightsFilePath || $rightsFilePath eq "") { confess("you need to specify --rights_xml file, which needs to be added"); } if (!defined $rightsFilePath || $rightsFilePath eq "") {
if (! -f $rightsFilePath) { confess("you need to specify --rights_xml file, status: is not a file"); } 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 # addMetaFile
if (@addMetaFile) { if (@addMetaFile) {
foreach my $file(@addMetaFile) { foreach my $file(@addMetaFile) {
if(! -f $file) { 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();
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment