eprints-dev: /home/dpavlin/mtoolkit/fix.sh [commit]
[eprints3-migration.git] / tsv2xp-xml.pl
index ccae475..6799778 100755 (executable)
@@ -11,8 +11,6 @@ use Data::Dump qw(dump);
 
 my $tsv_file = ( glob 'items.*' )[0];
 
-our $eprintsid = 700;
-
 my $xml = read_file 'ep-xml.xml';
 my @files = read_file "files.txt";
 
@@ -69,10 +67,21 @@ while(<$tsv>) {
                $file .= $1 if $full_path =~ m/(\.\w+)$/;
        }
 
+       my $subject;
+       if ( $file =~ m/(\w+)/ ) {
+               $_ = $1;
+               $subject =
+                       m/bib/i    ? 'IZBIB' :
+                       m/in[fo]/i ? 'IZDHI' :
+                       m/muz/i    ? 'IZMUZ' :
+                       m/arh/i    ? 'IZARH' :
+                       die "unknown subject: $2";
+       }
+
        my $c = $col;
-       $header2col->{'eprintsid'} = $c; $v[$c++] = $eprintsid++;
        $header2col->{'file'} = $c; $v[$c++] = $file;
        $header2col->{'full_path'} = $c; $v[$c++] = $full_path;
+       $header2col->{'subject'} = $c; $v[$c++] = $subject;
 
        my $eprints = $xml;
        while ( $eprints =~ s/<!-- "(.+?)" -->/interpolate($1)/seg ) {
@@ -80,6 +89,7 @@ while(<$tsv>) {
        }
 
        $eprints =~ s{<documents>.+</documents>}{<!-- no documents -->}s if ! $full_path;
+       $eprints =~ s{<subjects>.+</subjects>}{<!-- no subjects -->}s if ! $subject;
 
        print $eprints;
 }