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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
SLUB_SIP_Builder
Commits
6183b6a3
Commit
6183b6a3
authored
5 years ago
by
Jens Steidl
Browse files
Options
Downloads
Patches
Plain Diff
- make script OS-independent (incomplete, just part one)
parent
249d74b1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/slubsipbuilder.pl
+21
-25
21 additions, 25 deletions
bin/slubsipbuilder.pl
with
21 additions
and
25 deletions
bin/slubsipbuilder.pl
+
21
−
25
View file @
6183b6a3
...
@@ -24,13 +24,11 @@ use 5.20.0;
...
@@ -24,13 +24,11 @@ use 5.20.0;
use
strict
;
use
strict
;
use
warnings
;
use
warnings
;
use
Archive::Zip::
SimpleZip
qw($SimpleZipError)
;
use
Archive::Zip::
SimpleZip
qw($SimpleZipError)
;
use
Cwd
qw(abs_path)
;
use
DateTime::Format::
ISO8601
;
use
DateTime::Format::
ISO8601
;
use
Digest::
MD5
qw(md5)
;
use
Digest::
MD5
qw(md5)
;
use
File::
Basename
;
use
File::
Basename
;
use
File::
Copy
qw(cp)
;
use
File::
Copy
qw(cp)
;
use
File::
Find
;
use
File::
Find
;
use
File::
Path
;
use
Path::
Tiny
;
use
Path::
Tiny
;
use
Getopt::
Long
;
use
Getopt::
Long
;
use
LWP::
UserAgent
;
# to get MARC data
use
LWP::
UserAgent
;
# to get MARC data
...
@@ -82,7 +80,9 @@ if ((!defined $ppn) && (!defined $noppn)) { confess("you need to specify a PPN
...
@@ -82,7 +80,9 @@ if ((!defined $ppn) && (!defined $noppn)) { confess("you need to specify a PPN
if
(
!
defined
$output
)
{
confess
("
you need to specify an output path, where the SIP will be stored
");
}
if
(
!
defined
$output
)
{
confess
("
you need to specify an output path, where the SIP will be stored
");
}
if
(
!
defined
$external_conservation_flag
)
{
$external_conservation_flag
=
"
false
";
}
else
{
$external_conservation_flag
=
"
true
";
}
if
(
!
defined
$external_conservation_flag
)
{
$external_conservation_flag
=
"
false
";
}
else
{
$external_conservation_flag
=
"
true
";
}
if
(
!
-
d
$directory
)
{
confess
("
you need to specify an IE directory, which needs to be archived, $!
");
}
if
(
!
-
d
$directory
)
{
confess
("
you need to specify an IE directory, which needs to be archived, $!
");
}
$directory
=
abs_path
(
$directory
);
$directory
=
path
(
$directory
)
->
realpath
->
stringify
;
path
(
$output
)
->
mkpath
;
$output
=
path
(
$output
)
->
realpath
->
stringify
;
if
(
$external_id
!~
m#^[a-z0-9]+$#
)
{
confess
("
you need to specify a valid external ID (^[a-z0-9]+
\$
)
");
}
if
(
$external_id
!~
m#^[a-z0-9]+$#
)
{
confess
("
you need to specify a valid external ID (^[a-z0-9]+
\$
)
");
}
if
(
$external_workflow
!~
m#^[a-z0-9]+$#
)
{
confess
("
you need to specify a valid external workflow (^[a-z0-9]+
\$
)
");
}
if
(
$external_workflow
!~
m#^[a-z0-9]+$#
)
{
confess
("
you need to specify a valid external workflow (^[a-z0-9]+
\$
)
");
}
if
(
!
$external_value_descr
)
{
confess
("
you need to specify an external value description (reason for archiving)
");
}
if
(
!
$external_value_descr
)
{
confess
("
you need to specify an external value description (reason for archiving)
");
}
...
@@ -176,19 +176,18 @@ sub get_mods_from ($$$$) { # $mods = ($url, $ppn, $searchkey, $recordschema)
...
@@ -176,19 +176,18 @@ sub get_mods_from ($$$$) { # $mods = ($url, $ppn, $searchkey, $recordschema)
my
$schema
=
shift
;
my
$schema
=
shift
;
# check xsl directory
# check xsl directory
my
$xsl_dir
=
dirname
(
__FILE__
)
.
'
/../xsl/
'
;
my
$xsl_dir
=
path
(
dirname
(
__FILE__
)
)
->
realpath
->
parent
->
child
("
xsl
")
->
stringify
;
if
(
!
-
d
$xsl_dir
)
{
if
(
!
-
d
$xsl_dir
)
{
say
"
Rebuilding XSL directory '
$xsl_dir
'
";
say
"
Rebuilding XSL directory '
$xsl_dir
'
";
mkpath
(
$xsl_dir
)
||
confess
("
could not mkdir '
$xsl_dir
', $!
");;
mkpath
(
$xsl_dir
)
||
confess
("
could not mkdir '
$xsl_dir
', $!
");;
}
}
$xsl_dir
=
abs_path
(
$xsl_dir
);
#### where to find XSLT
#### where to find XSLT
my
$marc_mods_url
=
'
http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl
';
my
$marc_mods_url
=
'
http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl
';
my
$marc_mods_path
=
"
$xsl_dir
/
"
.
basename
(
$marc_mods_url
);
my
$marc_mods_path
=
path
(
$xsl_dir
)
->
child
(
basename
(
$marc_mods_url
)
)
->
stringify
;
my
$marc_mods_patched_path
=
"
$xsl_dir
/
"
.
basename
(
$marc_mods_url
,
"
.xsl
")
.
"
.patched.xsl
";
my
$marc_mods_patched_path
=
path
(
$xsl_dir
)
->
child
(
basename
(
$marc_mods_url
,"
.xsl
")
.
"
.patched.xsl
"
)
->
stringify
;
my
$marc_utils_url
=
'
http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl
';
my
$marc_utils_url
=
'
http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl
';
my
$marc_utils_path
=
"
$xsl_dir
/
"
.
basename
(
$marc_utils_url
);
my
$marc_utils_path
=
path
(
$xsl_dir
)
->
child
(
basename
(
$marc_utils_url
)
)
->
stringify
;
my
$ua
=
LWP::
UserAgent
->
new
;
my
$ua
=
LWP::
UserAgent
->
new
;
$ua
->
agent
("
MyApp/0.1
");
$ua
->
agent
("
MyApp/0.1
");
...
@@ -276,15 +275,14 @@ sub main {
...
@@ -276,15 +275,14 @@ sub main {
$file_date
=~
s/T/_/g
;
# replace 'T' with '_'
$file_date
=~
s/T/_/g
;
# replace 'T' with '_'
$file_date
=~
s/:/-/g
;
# replace ':' with '-'
$file_date
=~
s/:/-/g
;
# replace ':' with '-'
# create output dir
# create output dir
if
(
!
-
d
$output
)
{
#~
if (! -d $output) {
mkpath
("
$output
")
||
confess
("
could not create SIP directory for '
$output
', $!
");
#~
mkpath("$output") || confess("could not create SIP directory for '$output', $!");
}
#~
}
$output
=
abs_path
(
$output
);
#~
$output = abs_path($output);
my
$sip_root_dir
=
(
defined
$ppn
)?
"
PPN-
${ppn}
_
${file_date}
"
:
"
ID-
${noppn}
_
${file_date}
";
my
$sip_root_dir
=
(
defined
$ppn
)?
"
PPN-
${ppn}
_
${file_date}
"
:
"
ID-
${noppn}
_
${file_date}
";
my
$content
=
"
$output
/
$sip_root_dir
/data
"
;
my
$content
=
path
(
$output
)
->
child
(
$sip_root_dir
)
->
child
("
data
")
->
stringify
;
if
(
!
defined
$as_zip
)
{
if
(
!
defined
$as_zip
)
{
mkpath
("
$output
/
$sip_root_dir
")
||
confess
("
could not create SIP directory for '
$output
/
$sip_root_dir
', $!
");
path
(
$content
)
->
mkpath
;
mkpath
("
$content
")
||
confess
("
could not create SIP subdirectory for '
$content
', $!
");
}
}
...
@@ -425,28 +423,26 @@ METS
...
@@ -425,28 +423,26 @@ METS
# compress if needed
# compress if needed
if
(
!
defined
$as_zip
)
{
if
(
!
defined
$as_zip
)
{
write_file
(
"
${output}
/
${sip_root_dir}
/sip.xml
"
,
$sip
);
write_file
(
path
(
$output
)
->
child
(
$sip_root_dir
)
->
child
("
sip.xml
")
->
stringify
,
$sip
);
# copy source to target
# copy source to target
foreach
my
$source
(
sort
keys
(
%filecopyhash
))
{
foreach
my
$source
(
sort
keys
(
%filecopyhash
))
{
my
$target
=
$filecopyhash
{
$source
}
->
{"
target
"};
my
$target
=
path
(
$filecopyhash
{
$source
}
->
{"
target
"})
->
stringify
;
# CHECK ON WINDOWS
my
$basename
=
dirname
(
$target
);
my
$basename
=
path
(
$target
)
->
parent
->
stringify
;
#say "cp $source, $target ($basename)";
if
(
!
-
d
$basename
)
{
if
(
!
-
d
$basename
)
{
mk
path
(
$basename
)
||
confess
("
could not mkdir '
$basename
', $!
")
;
path
(
$basename
)
->
mkpath
;
}
}
cp
(
$source
,
$target
,
buffer
)
||
confess
("
could not copy from '
$source
' to '
$target
', $!
");
cp
(
$source
,
$target
,
buffer
)
||
confess
("
could not copy from '
$source
' to '
$target
', $!
");
}
}
say
"
SIP '
$sip_root_dir
' build successfully in '
$output
'
";
say
"
SIP '
$sip_root_dir
' build successfully in '
$output
'
";
}
else
{
}
else
{
# compress it
# compress it
my
$zip_file_path
=
"
$output
/
$sip_root_dir
.zip
";
my
$zip_file_path
=
path
(
$output
)
->
child
("
$sip_root_dir
.zip
"
)
->
stringify
;
my
$zip
=
Archive::Zip::
SimpleZip
->
new
(
$zip_file_path
,
Zip64
=>
1
);
my
$zip
=
Archive::Zip::
SimpleZip
->
new
(
$zip_file_path
,
Zip64
=>
1
);
$zip
->
addString
(
$sip
,
Name
=>
"
$sip_root_dir
/sip.xml
"
);
$zip
->
addString
(
$sip
,
Name
=>
path
(
$sip_root_dir
)
->
child
("
sip.xml
")
->
stringify
);
# copy source to target
# copy source to target
foreach
my
$source
(
sort
keys
(
%filecopyhash
))
{
foreach
my
$source
(
sort
keys
(
%filecopyhash
))
{
my
$target
=
"
$sip_root_dir
/
"
.
$filecopyhash
{
$source
}
->
{"
relative
"};
my
$target
=
path
(
$sip_root_dir
)
->
child
(
$filecopyhash
{
$source
}
->
{"
relative
"})
->
stringify
;
# CHECK ON WINDOWS
my
$basename
=
dirname
(
$target
);
my
$basename
=
path
(
$target
)
->
parent
->
stringify
;
#say "cp $source, $target ($basename)";
$zip
->
add
(
$source
,
Name
=>
$target
)
||
confess
("
could not zip copy from '
$source
' to '
$target
', $!
");
$zip
->
add
(
$source
,
Name
=>
$target
)
||
confess
("
could not zip copy from '
$source
' to '
$target
', $!
");
}
}
unless
(
$zip
->
close
())
{
unless
(
$zip
->
close
())
{
...
...
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