version 1.1, 2006/06/27 18:06:41
|
version 1.5, 2017/03/16 17:00:43
|
Line 1
|
Line 1
|
#!/usr/local/bin/perl -w |
#!/usr/bin/perl -w |
|
|
use strict; |
use strict; |
use XML::LibXML; |
use XML::LibXML; |
|
|
use lib '/usr/local/mpiwg/archive_devel'; |
use lib '/usr/local/mpiwg/archive'; |
use MPIWGStor; |
use MPIWGStor; |
|
|
# make output unbuffered |
# make output unbuffered |
$|=1; |
$|=1; |
|
|
# program version |
# program version |
my $version = "0.1 (27.6.2006 ROC)"; |
my $version = "0.3 (11.12.2006 ROC)"; |
my $help = |
my $help = |
"use: checkmeta [options] dir |
"use: changemeta [options] dir |
options: |
options: |
-debug show debugging info |
-debug show debugging info |
-dry-run simulate, dont'do anything |
-dry-run simulate, dont'do anything |
-access=free adds free access tag (use access=mpiwg for restricted access) |
-access=free set free access tag (use access=mpiwg for restricted access) |
|
-derived-from=/mpiwg/archive/data/DBDDHKP |
|
-production-comment=\"scanned with flatbed scanner\" |
"; |
"; |
logger("INFO", "checkmeta $version"); |
logger("INFO", "changemeta $version"); |
|
|
|
|
####################################################### |
####################################################### |
Line 43 logger('DEBUG', "dry-run: $dry_run");
|
Line 45 logger('DEBUG', "dry-run: $dry_run");
|
my $access_type = (exists $$args{'access'}) ? $$args{'access'} : ""; |
my $access_type = (exists $$args{'access'}) ? $$args{'access'} : ""; |
logger('DEBUG', "access: $access_type"); |
logger('DEBUG', "access: $access_type"); |
|
|
|
# derived-from |
|
my $derived_from = (exists $$args{'derived-from'}) ? $$args{'derived-from'} : ""; |
|
logger('DEBUG', "derived-from: $derived_from"); |
|
|
|
# production-comment |
|
my $production_comment = (exists $$args{'production-comment'}) ? $$args{'production-comment'} : ""; |
|
logger('DEBUG', "production-comment: $production_comment"); |
|
|
# index.meta namespace (not really implemented!) |
# index.meta namespace (not really implemented!) |
my $namespace = ""; |
my $namespace = ""; |
|
|
Line 81 sub change_access {
|
Line 91 sub change_access {
|
my $parent_tag = $index_root->findnodes('//meta/access-conditions')->get_node(1); |
my $parent_tag = $index_root->findnodes('//meta/access-conditions')->get_node(1); |
if ($parent_tag) { |
if ($parent_tag) { |
my $access_tag = $parent_tag->findnodes('access')->get_node(1); |
my $access_tag = $parent_tag->findnodes('access')->get_node(1); |
|
# remove access tag if it exists |
if ($access_tag) { |
if ($access_tag) { |
$parent_tag->removeChild($access_tag); |
$parent_tag->removeChild($access_tag); |
} |
} |
Line 88 sub change_access {
|
Line 99 sub change_access {
|
$parent_tag = create_element_path('meta/access-conditions', $index_root, $namespace); |
$parent_tag = create_element_path('meta/access-conditions', $index_root, $namespace); |
} |
} |
|
|
|
# add new access tag (if $access_Type is not empty) |
if ($access_type eq "free") { |
if ($access_type eq "free") { |
create_element_path('access@type=free', $parent_tag, $namespace); |
create_element_path('access@type=free', $parent_tag, $namespace); |
} elsif (length $access_type > 0) { |
} elsif (length $access_type > 0) { |
Line 97 sub change_access {
|
Line 109 sub change_access {
|
$xml_changed++ |
$xml_changed++ |
} |
} |
|
|
|
# |
|
# sets derived-from tag to given value |
|
# removes tag if derived_from is empty |
|
# |
|
sub change_derived { |
|
my ($derived_from, $index_root) = @_; |
|
|
|
my $derived_tag = $index_root->findnodes('derived-from')->get_node(1); |
|
# remove derived tag if it exists |
|
if ($derived_tag) { |
|
$index_root->removeChild($derived_tag); |
|
} |
|
|
|
# add new derived tag (if $derived_Type is not empty) |
|
if (length $derived_from > 0) { |
|
create_text_path('derived-from/archive-path', $derived_from, $index_root, $namespace); |
|
} |
|
$xml_changed++ |
|
} |
|
|
|
# |
|
# sets production-comment tag to given value |
|
# removes production tag if production_comment is empty |
|
# |
|
sub change_production { |
|
my ($production_comment, $index_root) = @_; |
|
|
|
my $parent_tag = $index_root->findnodes('//meta/image-acquisition')->get_node(1); |
|
if ($parent_tag) { |
|
my $production_tag = $parent_tag->findnodes('production-comment')->get_node(1); |
|
# remove production tag if it exists |
|
if ($production_tag) { |
|
$parent_tag->removeChild($production_tag); |
|
} |
|
} else { |
|
$parent_tag = create_element_path('meta/image-acquisition', $index_root, $namespace); |
|
} |
|
|
|
# add new production tag (if $production_comment is not empty) |
|
if (length $production_comment > 0) { |
|
create_text_path('production-comment', $production_comment, $parent_tag, $namespace); |
|
} |
|
$xml_changed++ |
|
} |
|
|
|
|
|
|
|
|
Line 119 if (-f "$docdir/index.meta") {
|
Line 176 if (-f "$docdir/index.meta") {
|
} |
} |
|
|
if ($access_type) { |
if ($access_type) { |
change_access($index_root); |
change_access($access_type, $index_root); |
|
} |
|
if ($derived_from) { |
|
change_derived($derived_from, $index_root); |
|
} |
|
if ($production_comment) { |
|
change_production($production_comment, $index_root); |
} |
} |
|
|
|
|
Line 134 if ($errcnt > 0) {
|
Line 197 if ($errcnt > 0) {
|
logger('DEBUG', "would write $docdir/index.meta"); |
logger('DEBUG', "would write $docdir/index.meta"); |
logger('DEBUG', $index_doc->toString(1)); |
logger('DEBUG', $index_doc->toString(1)); |
} else { |
} else { |
#write_xml($index_doc, "$docdir/index.meta"); |
write_xml($index_doc, "$docdir/index.meta"); |
} |
} |
logger("DONE", "changed index file successfully!"); |
logger("DONE", "changed index file successfully!"); |
} else { |
} else { |