diff --git a/bin/slubsipbuilderbagit.pl b/bin/slubsipbuilderbagit.pl index 033bd53f84b4aea20223a50bde844fe9604b269e..15b0c259a721d47c8562a3ace2d2ba9918abbd0d 100644 --- a/bin/slubsipbuilderbagit.pl +++ b/bin/slubsipbuilderbagit.pl @@ -118,34 +118,34 @@ if ($help) { pod2usage(1); } if ($man) { pod2usage(-exitval => 0, -verbose => 2); } # save 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"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify a --save_option, available <replace> or <copy> or <move>", "", "red"); exit 1; } # ieDirectory if (!defined $ieDirectory || $ieDirectory eq "") { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --IE_directory, which needs to be archived", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify an --IE_directory, which needs to be archived", "", "red"); exit 1; } if (! -d $ieDirectory) { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify a valid --IE_directory, status: is not a directory", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify a valid --IE_directory, status: is not a directory", "", "red"); exit 1; } # outputPath if (!defined $outputPath && ($save eq "copy" || $save eq "move")) { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --SIP_output_path, where the SIP will be stored", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify an --SIP_output_path, where the SIP will be stored", "", "red"); exit 1; } if (defined $outputPath && $outputPath eq "" && ($save eq "copy" || $save eq "move")) { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --SIP_output_path, where the SIP will be stored", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify an --SIP_output_path, where the SIP will be stored", "", "red"); exit 1; } # ppn, noppn if (defined $ppn && defined $noppn) { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you can only specify either --ppn or --noppn", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you can only specify either --ppn or --noppn", "", "red"); exit 1; } 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"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify a PPN with --ppn or use --noppn", "", "red"); exit 1; } @@ -155,22 +155,22 @@ utf8::decode($sipVersion); push @addBagInfo, {'SLUBArchiv-sipVersion' => $sipVersion}; # externalWorkflow if (!defined $externalWorkflow || $externalWorkflow eq "") { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify external workflow", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify external workflow", "", "red"); exit 1; } 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"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify a valid --external_workflow (^[a-z0-9_-]+\$)", "", "red"); exit 1; } utf8::decode($externalWorkflow); push @addBagInfo, {'SLUBArchiv-externalWorkflow' => $externalWorkflow}; # externalId if (!defined $externalId || $externalId eq "") { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify external ID", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify external ID", "", "red"); exit 1; } 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"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify a valid --external_id (^[a-z0-9_-]+\$)", "", "red"); exit 1; } utf8::decode($externalId); @@ -193,18 +193,18 @@ utf8::decode($hasConservationReason); push @addBagInfo, {'SLUBArchiv-hasConservationReason' => $hasConservationReason}; # archivalValueDescription if (!defined $archivalValueDescription || $archivalValueDescription eq "") { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify an --external_value_descr (reason for archiving)", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify an --external_value_descr (reason for archiving)", "", "red"); exit 1; } utf8::decode($archivalValueDescription); push @addBagInfo, {'SLUBArchiv-archivalValueDescription' => $archivalValueDescription}; # rightsVersion if (!defined $rightsVersion || $rightsVersion eq "") { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify --rights_version", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify --rights_version", "", "red"); exit 1; } if($rightsVersion ne "1.0") { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: invalid --rights_version, supported version <1.0>", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: invalid --rights_version, supported version <1.0>", "", "red"); exit 1; } utf8::decode($rightsVersion); @@ -213,7 +213,7 @@ push @addBagInfo, {'SLUBArchiv-rightsVersion' => $rightsVersion}; if (@addKeyValue) { foreach my $zeile(@addKeyValue) { if($zeile !~ m#^.*:.*$#) { # : must be minimum once present - 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"); + 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"); exit 1; } utf8::decode($zeile); @@ -228,18 +228,18 @@ if (@addKeyValue) { $key eq 'SLUBArchiv-hasConservationReason' || $key eq 'SLUBArchiv-archivalValueDescription' || $key eq 'SLUBArchiv-rightsVersion'){ - 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"); + 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"); exit 1; } if($key eq 'Bag-Count'){ - 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"); + 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"); exit 1; } if($key eq 'Bag-Group-Identifier'){ - 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"); + 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"); exit 1; } push @addBagInfo, {$key => $value}; @@ -249,18 +249,18 @@ if (@addKeyValue) { # rightsFilePath 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"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify --rights_xml file, which needs to be added", "", "red"); exit 1; } if (! -f $rightsFilePath) { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: you need to specify --rights_xml file, status: is not a file", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: you need to specify --rights_xml file, status: is not a file", "", "red"); exit 1; } # addMetaFile if (@addMetaFile) { foreach my $file(@addMetaFile) { if(! -f $file) { - SLUB::LZA::SIPBuilderBagIt::print_scalar_data("", "ERROR: file $file at --add_meta_file, is not a file or could not be found", "", "red"); + SLUB::LZA::SIPBuilderBagIt::print_scalar_data( "ERROR: file $file at --add_meta_file, is not a file or could not be found", "", "red"); exit 1; } } diff --git a/lib/SLUB/LZA/SIPBuilderBagIt.pm b/lib/SLUB/LZA/SIPBuilderBagIt.pm index 62f4e3ddee002fcc8afa39cf6dcf4d54913dc173..44e66c0bd216d8ab68efe96526ac81906645c272 100644 --- a/lib/SLUB/LZA/SIPBuilderBagIt.pm +++ b/lib/SLUB/LZA/SIPBuilderBagIt.pm @@ -116,7 +116,7 @@ sub get_marc21_from_catalogue($ppn){ if ($@) { # error say "$@" unless (! $with_debug); if ($@ =~ m#ERROR: Did not get any <recordData/> for PPN#) { - print_scalar_data("", "WARNING: '$ppn' not a SWB PPN, fallback to K10plus", "", "yellow"); + print_scalar_data( "WARNING: '$ppn' not a SWB PPN, fallback to K10plus", "", "yellow"); $use_fallback = 1; } else { @@ -131,7 +131,7 @@ sub get_marc21_from_catalogue($ppn){ if ($@) { # error say "$@" unless (!$with_debug); if ($@ =~ m#ERROR: Did not get any <recordData/> for PPN#) { - print_scalar_data("", "ERROR: '$ppn' also not a K10plus PPN", "", "red"); + print_scalar_data( "ERROR: '$ppn' also not a K10plus PPN", "", "red"); exit 1; } else { @@ -140,7 +140,7 @@ sub get_marc21_from_catalogue($ppn){ } } - print_scalar_data("", "INFO: Found metadata for PPN '$ppn'", "", "white"); + print_scalar_data( "INFO: Found metadata for PPN '$ppn'", "", "white"); return $marc21; } @@ -213,7 +213,7 @@ sub createDir($path){ if(! -d $path && ! -f $path){ eval { path($path)->mkpath; }; if ($@) { # error - print_scalar_data("", "ERROR: Failed to create directory '$path'.", "", "red"); + print_scalar_data( "ERROR: Failed to create directory '$path'.", "", "red"); die $@; } } @@ -237,8 +237,8 @@ sub copyFilesToMeta($ppn, $metaPath,$rightsFilePath,$aRefAddMetaFile,$marc21){ $i++; } } - print_scalar_data("", "WARNING: Renaming " . $meta_file_name . " to $i.xml, because meta filename <rights.xml> or <marc21.xml> is reserved.", "", "yellow"); - print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + print_scalar_data( "WARNING: Renaming " . $meta_file_name . " to $i.xml, because meta filename <rights.xml> or <marc21.xml> is reserved.", "", "yellow"); + print_scalar_data( "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); copy($file, $metaPath) or die "Copy failed: $!"; rename("$metaPath/$meta_file_name", "$metaPath/$i.xml"); $i++; @@ -256,8 +256,8 @@ sub copyFilesToMeta($ppn, $metaPath,$rightsFilePath,$aRefAddMetaFile,$marc21){ # rights.xml if(basename($rightsFilePath) ne "rights.xml"){ my $rights_name = basename($rightsFilePath); - print_scalar_data("", "WARNING: Renaming " . $rights_name . " to rights.xml, because meta filename <rights.xml> is required.", "", "yellow"); - print_scalar_data("", "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); + print_scalar_data( "WARNING: Renaming " . $rights_name . " to rights.xml, because meta filename <rights.xml> is required.", "", "yellow"); + print_scalar_data( "INFO: Read Docu for more information at https://slubarchiv.slub-dresden.de/technische-standards-fuer-die-ablieferung-von-digitalen-dokumenten/", "", "white"); copy($rightsFilePath, $metaPath) or die "Copy failed: $!"; rename("$metaPath/$rights_name", "$metaPath/rights.xml"); }else{ @@ -292,19 +292,12 @@ sub validateRightsXML($rightsFilePathString,$xsdName){ return 1; } -sub print_scalar_data($header,$p,$arrRef,$pColor){ +sub print_scalar_data($p,$arrRef,$pColor){ my $priority = 0; - # header - if($header ne ""){ - print "----------------------------------------------------------------------------------\n" if $priority >= $VERBOSE; - printf "%" . length($header) . "s\n", colored($header, 'bold green') if $priority >= $VERBOSE; - print "----------------------------------------------------------------------------------\n" if $priority >= $VERBOSE; - } # paragraph if(($p ne "") && ($arrRef eq "")){ printf "%" . length($p) . "s\n", colored($p, "bold $pColor") if $priority >= $VERBOSE; } - # paragraph with converted array if(($p ne "") && ($arrRef ne "")){ my $string = ""; @@ -318,7 +311,6 @@ sub print_scalar_data($header,$p,$arrRef,$pColor){ my $body = $p . $string; printf "%" . length($body) . "s\n", colored($body, "bold $pColor") if $priority >= $VERBOSE; } - return 1; } @@ -330,7 +322,7 @@ sub create_slub_bagit($bagPath,$refAddBagInfo){ my $oArchiveBagIt = Archive::BagIt->make_bag($bagPath); $oArchiveBagIt->bag_info($refAddBagInfo); $oArchiveBagIt->store(); - print_scalar_data("", "SUCCESS: SLUB SIP at $bagPath build successfully!", "", "green"); + print_scalar_data( "SUCCESS: SLUB SIP at $bagPath build successfully!", "", "green"); return 1; } @@ -351,7 +343,7 @@ sub __buildBag ($ppn, $noppn, $rightsFilePath, $aRefAddMetaFile, $refAddBagInfo, # metadata warnings SLUB::LZA::SIPBuilderBagIt::checkForTitle(\@addBagInfo); # create slub bagit - print_scalar_data("", "INFO: building SIP...", "", "white"); + print_scalar_data( "INFO: building SIP...", "", "white"); SLUB::LZA::SIPBuilderBagIt::create_slub_bagit($bagPath, \@addBagInfo); return 1; } @@ -362,7 +354,7 @@ sub buildBagWithCopyOption($ppn,$noppn,$ieDirectory,$rightsFilePath,$aRefAddMeta # create data dir SLUB::LZA::SIPBuilderBagIt::createDir($dataPath); # copy payload files to data - print_scalar_data("", "INFO: copying original data...", "", "white"); + print_scalar_data( "INFO: copying original data...", "", "white"); dircopy($ieDirectory, $dataPath) || die ("Error coping $ieDirectory to $dataPath"); __buildBag($ppn,$noppn,$rightsFilePath,$aRefAddMetaFile,$refAddBagInfo,$bagPath,$metaPath); return 1; @@ -372,7 +364,7 @@ sub buildBagWithMoveOption($ppn,$noppn,$ieDirectory,$rightsFilePath,$aRefAddMeta # create bag dir SLUB::LZA::SIPBuilderBagIt::createDir($bagPath); # move payloads to data dir (which is automatically renamed from IE Directory) - print_scalar_data("", "INFO: moving original data...", "", "white"); + print_scalar_data( "INFO: moving original data...", "", "white"); dirmove($ieDirectory, $dataPath) || die ("Error moving $ieDirectory to $dataPath"); __buildBag($ppn,$noppn,$rightsFilePath,$aRefAddMetaFile,$refAddBagInfo,$bagPath,$metaPath); return 1; @@ -382,7 +374,7 @@ sub buildBagWithReplaceOption($ppn,$noppn,$ieDirectory,$rightsFilePath,$aRefAddM # create bag dir SLUB::LZA::SIPBuilderBagIt::createDir($bagPath); # move payloads to data dir (which is automatically renamed from IE Directory) - print_scalar_data("", "INFO: moving original data...", "", "white"); + print_scalar_data( "INFO: moving original data...", "", "white"); dirmove($ieDirectory, $dataPath) || die ("Error moving $ieDirectory to $dataPath"); __buildBag($ppn,$noppn,$rightsFilePath,$aRefAddMetaFile,$refAddBagInfo,$bagPath,$metaPath); return 1; @@ -396,7 +388,7 @@ sub checkForTitle($key_hash_list_aref){ } # check for title if (none { lc($_) =~ m/^title/ } @keys) { - print_scalar_data("", "WARNING: No Title given. Please consider adding a human-readable title with '--add_key_value=Title:YOUR-TITLE'", "", "yellow"); + print_scalar_data( "WARNING: No Title given. Please consider adding a human-readable title with '--add_key_value=Title:YOUR-TITLE'", "", "yellow"); return 0; } return 1;