changeset 30:398ef4b8f072

added -online-base option to makemeta-lib
author casties
date Mon, 12 Jun 2006 19:01:39 +0200
parents f77f6cb40c4f
children de63fae5f483
files MPIWGStor.pm makemeta-lib.pl
diffstat 2 files changed, 27 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGStor.pm	Tue May 16 21:56:32 2006 +0200
+++ b/MPIWGStor.pm	Mon Jun 12 19:01:39 2006 +0200
@@ -155,15 +155,20 @@
 
 
 #
-# $name = sstrip($name)
+# $name = sstrip($name, $slash)
 #
 # strips leading and trailing whitespace from $name
+# replaces double slashes with single ones with $slash.
 #
 sub sstrip {
-    my ($name) = @_;
+    my ($name, $slash) = @_;
     
     if ($name =~ /^\s*(.*?)\s*$/) {
-	return $1;
+	$name = $1;
+    }
+    if ($slash) {
+	# trim multiple slashes
+	$name =~ s/\/+/\//g;
     }
     return $name;
 }
--- a/makemeta-lib.pl	Tue May 16 21:56:32 2006 +0200
+++ b/makemeta-lib.pl	Mon Jun 12 19:01:39 2006 +0200
@@ -10,13 +10,14 @@
 $|=1;
 
 # program version
-my $version = "0.2.4 (16.5.2006 ROC)";
+my $version = "0.2.5 (9.6.2006 ROC)";
 my $help = 
 "use: makemeta-lib [options] file.xml
 options:
   -debug  show debugging info
   -dry-run  simulate, dont'do anything
   -online-mode  mode for creating online/permanent files
+  -online-base=dir  base directory for online ids (for online mode)
   -cw-mode  mode for copying einstein_cw archive documents
   -digifiles-mode  mode for copying files from digifiles
   -map-file=mapfile.xml  digilib mapping file (for digifiles mode)
@@ -140,6 +141,9 @@
 # use online mode
 my $online_mode = (exists $$args{'online-mode'}) ? $$args{'online-mode'} : 0;
 logger('DEBUG', "online_mode: $online_mode");
+# online base dir
+my $online_base_dir = (exists $$args{'online-base'}) ? $$args{'online-base'} : "";
+logger('DEBUG', "online_base_dir: $online_base_dir");
 
 # use einstein-cw mode
 my $cw_mode = (exists $$args{'cw-mode'}) ? $$args{'cw-mode'} : 0;
@@ -174,7 +178,7 @@
     exit 1;
 }
 # strip double slashes
-$infile =~ s/\/\//\//;
+$infile = sstrip($infile, 1);
 if (! -f $infile) {
     logger("ABORT", "input file \'$infile\' doesn't exist!");
     exit 1;
@@ -277,15 +281,21 @@
 
 sub find_permanent_dir {
     my ($input_node) = @_;
+    my $online_id = sstrip($input_node->findvalue("fm:$online_id_field"));
+    # try online_base_dir + online_id first
+    if (($online_base_dir)&&($online_id)) {
+	my $dir = sstrip("$online_base_dir/$online_id", 1);
+	return $dir;
+    }
+    # then online_url
     my $online_base = '/mpiwg/online/permanent';
-    my $src_dir = find_online_dir($input_node, $online_base, 'pageimg');
-    my $dest_id = sstrip($input_node->findvalue("fm:$online_id_field"));
-    if ((! $dest_id)||(! $src_dir)) {
-	logger('ERROR', "no ID field for online permanent entry");
+    my $online_dir = find_online_dir($input_node, $online_base, 'pageimg');
+    if ((! $online_dir)) {
+	logger('ERROR', "no ID or URL for online permanent entry");
 	$errcnt++;
 	return;
     }
-    my $dir = "$online_base/$src_dir";
+    my $dir = sstrip("$online_base/$online_dir", 1);
     return $dir;
 }
 
@@ -314,7 +324,8 @@
     if ($online_dir) {
 	$online_dir =~ s/\/$//; # strip ending slashes
 	if ($page_dir) {
-	  $online_dir =~ s/\/${page_dir}$//;
+	    # strip page_dir
+	    $online_dir =~ s/\/${page_dir}$//;
 	}
 	#logger("DEBUG", "dir: $base_dir/$online_dir");
 	if (-d "$base_dir/$online_dir") {