Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SLUB_SIP_Builder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
SLUB_SIP_Builder
Commits
1d24bd60
Commit
1d24bd60
authored
6 years ago
by
Jens Steidl
Browse files
Options
Downloads
Patches
Plain Diff
- moved argument checks to the beginning
- created main()
parent
388bea3f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/slubsipbuilder.pl
+170
-151
170 additions, 151 deletions
bin/slubsipbuilder.pl
with
170 additions
and
151 deletions
bin/slubsipbuilder.pl
+
170
−
151
View file @
1d24bd60
...
...
@@ -40,7 +40,58 @@ use XML::LibXSLT;
use
XML::
XPath
;
use
constant
buffer
=>
100
*
1024
*
1024
;
# use 100MB as Buffer
my
$with_debug
=
0
;
#===============================================================================
my
$directory
;
my
$ppn
;
my
$noppn
;
my
$output
;
my
$url
;
my
$as_zip
;
my
$external_id
;
my
$external_workflow
;
my
$external_isil
=
"";
my
$external_value_descr
;
my
$external_conservation_flag
;
my
$with_debug
;
my
$help
;
my
$man
;
our
$VERSION
=
'
1.1
';
GetOptions
(
"
IE_directory=s
"
=>
\
$directory
,
"
ppn=s
"
=>
\
$ppn
,
"
noppn=s
"
=>
\
$noppn
,
"
SIP_output_path=s
"
=>
\
$output
,
"
as_zip
"
=>
\
$as_zip
,
"
url=s
"
=>
\
$url
,
"
external_id=s
"
=>
\
$external_id
,
"
external_workflow=s
"
=>
\
$external_workflow
,
"
external_ISIL=s
"
=>
\
$external_isil
,
"
external_value_descr=s
"
=>
\
$external_value_descr
,
"
external_conservation_flag
"
=>
\
$external_conservation_flag
,
"
debug
"
=>
\
$with_debug
,
"
help|?
"
=>
\
$help
,
"
man
"
=>
\
$man
,
)
or
pod2usage
(
2
);
if
(
$help
)
{
pod2usage
(
1
);
}
if
(
$man
)
{
pod2usage
(
-
exitval
=>
0
,
-
verbose
=>
2
);
}
if
(
!
defined
$directory
)
{
confess
("
you need to specify an IE directory, which needs to be archived
");
}
if
(
!
defined
$ppn
&&
!
defined
$noppn
)
{
confess
("
you need to specify a PPN, which exists in SWB catalogue
");
}
if
(
defined
$ppn
&&
defined
$noppn
)
{
confess
("
you could only use --ppn=foo or --noppn=bar
");
}
if
(
!
defined
$output
)
{
confess
("
you need to specify an output path, where the SIP will be stored
");
}
if
(
$output
!~
m#^/#
)
{
confess
("
you need to specify an output path using absoluet paths, $!
");
}
if
(
!
defined
$url
)
{
$url
=
"
http://swb.bsz-bw.de/sru/DB=2.1/username=/password=/
";}
if
(
!
defined
$external_conservation_flag
)
{
$external_conservation_flag
=
"
false
";
}
else
{
$external_conservation_flag
=
"
true
";
}
# additional checks
if
(
!
-
d
$directory
)
{
confess
("
you need to specify an IE directory, which needs to be archived, $!
");
}
if
(
$directory
!~
m#^/#
)
{
confess
("
you need to specify an IE directory using absoluet paths, $!
");
}
#if (! -d $output) { confess("you need to specify an output path, where the SIP will be stored, $!"); }
#===============================================================================
# write data to file (UTF-8)
sub
write_file
($$)
{
#
my
$filename
=
$_
[
0
];
...
...
@@ -183,60 +234,21 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn)
#===============================================================================
my
$directory
;
my
$ppn
;
my
$noppn
;
my
$output
;
my
$url
;
my
$as_zip
;
my
$external_id
;
my
$external_workflow
;
my
$external_isil
=
"";
my
$external_value_descr
;
my
$external_conservation_flag
;
our
$VERSION
=
'
1.0
';
GetOptions
(
"
IE_directory=s
"
=>
\
$directory
,
"
ppn=s
"
=>
\
$ppn
,
"
noppn=s
"
=>
\
$noppn
,
"
SIP_output_path=s
"
=>
\
$output
,
"
as_zip
"
=>
\
$as_zip
,
"
url=s
"
=>
\
$url
,
"
external_id=s
"
=>
\
$external_id
,
"
external_workflow=s
"
=>
\
$external_workflow
,
"
external_ISIL=s
"
=>
\
$external_isil
,
"
external_value_descr=s
"
=>
\
$external_value_descr
,
"
external_conservation_flag
"
=>
\
$external_conservation_flag
,
"
debug
"
=>
\
$with_debug
,
"
help
"
=>
sub
{
pod2usage
(
1
);
exit
(
0
);
},
)
or
pod2usage
(
2
);
if
(
!
defined
$directory
)
{
confess
("
you need to specify an IE directory, which needs to be archived
");
}
if
(
!
defined
$ppn
&&
!
defined
$noppn
)
{
confess
("
you need to specify a PPN, which exists in SWB catalogue
");
}
if
(
defined
$ppn
&&
defined
$noppn
)
{
confess
("
you could only use --ppn=foo or --noppn=bar
");
}
if
(
!
defined
$output
)
{
confess
("
you need to specify an output path, where the SIP will be stored
");
}
if
(
$output
!~
m#^/#
)
{
confess
("
you need to specify an output path using absoluet paths, $!
");
}
if
(
!
defined
$url
)
{
$url
=
"
http://swb.bsz-bw.de/sru/DB=2.1/username=/password=/
";}
if
(
!
defined
$external_conservation_flag
)
{
$external_conservation_flag
=
"
false
";
}
else
{
$external_conservation_flag
=
"
true
";
}
# additional checks
if
(
!
-
d
$directory
)
{
confess
("
you need to specify an IE directory, which needs to be archived, $!
");
}
if
(
$directory
!~
m#^/#
)
{
confess
("
you need to specify an IE directory using absoluet paths, $!
");
}
#if (! -d $output) { confess("you need to specify an output path, where the SIP will be stored, $!"); }
sub
main
{
# get date
my
$export_to_archive_date
=
DateTime
->
now
->
iso8601
();
#
my
$file_date
=
$export_to_archive_date
;
$file_date
=~
s/T/_/g
;
$file_date
=~
s/:/-/g
;
# create output dir
mkpath
"
$output
"
||
confess
("
could not create SIP directory for '
$output
', $!
");
if
(
!
-
d
$output
)
{
mkpath
("
$output
")
||
confess
("
could not create SIP directory for '
$output
', $!
");
}
my
$sip_root_dir
=
"
PPN-
${ppn}
_
${file_date}
";
my
$content
=
"
$output
/
$sip_root_dir
/data
";
if
(
!
defined
$as_zip
)
{
mkpath
"
$output
/
$sip_root_dir
"
||
confess
("
could not create SIP directory for '
$output
/
$sip_root_dir
', $!
");
mkpath
"
$content
"
||
confess
("
could not create SIP subdirectory for '
$content
', $!
");
mkpath
(
"
$output
/
$sip_root_dir
"
)
||
confess
("
could not create SIP directory for '
$output
/
$sip_root_dir
', $!
");
mkpath
(
"
$content
"
)
||
confess
("
could not create SIP subdirectory for '
$content
', $!
");
}
...
...
@@ -245,7 +257,7 @@ my $mods;
if
(
defined
$ppn
)
{
$mods
=
get_mods_from
(
$url
,
$ppn
);
if
(
1
==
$with_debug
)
{
write_file
("
DEBUG_
${ppn}
_mods.xml
",
{
binmode
=>
'
:utf8
'},
$mods
);
write_file
("
DEBUG_
${ppn}
_mods.xml
",
$mods
);
}
# remove the <xml /> from beginning of the answer
$mods
=~
s#<\?xml version="1.0" encoding="UTF-8"\?>#<!-- removed xml header from mods part -->#
;
...
...
@@ -377,14 +389,14 @@ METS
# compress if needed
if
(
!
defined
$as_zip
)
{
write_file
(
"
${output}
/
${sip_root_dir}
/sip.xml
",
{
binmode
=>
'
:utf8
'},
$sip
);
write_file
(
"
${output}
/
${sip_root_dir}
/sip.xml
",
$sip
);
# copy source to target
foreach
my
$source
(
sort
keys
(
%filecopyhash
))
{
my
$target
=
$filecopyhash
{
$source
}
->
{"
target
"};
my
$basename
=
dirname
(
$target
);
#say "cp $source, $target ($basename)";
if
(
!
-
d
$basename
)
{
mkpath
$basename
||
confess
("
could not mkdir '
$basename
', $!
");
mkpath
(
$basename
)
||
confess
("
could not mkdir '
$basename
', $!
");
}
cp
(
$source
,
$target
,
buffer
)
||
confess
("
could not copy from '
$source
' to '
$target
', $!
");
}
...
...
@@ -406,8 +418,15 @@ if (!defined $as_zip) {
}
say
"
SIP '
$sip_root_dir
' build successfully in '
$zip_file_path
'
";
}
}
#===============================================================================
main
();
#===============================================================================
__END__
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment