[21205] | 1 | #!/usr/bin/perl -w
|
---|
[20983] | 2 |
|
---|
[21205] | 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # pharos-imageis-add.pl --
|
---|
| 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
| 10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
| 26 | ###########################################################################
|
---|
[20983] | 27 |
|
---|
[21205] | 28 | BEGIN {
|
---|
| 29 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 30 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
[21259] | 31 | die "PHAROSIS_SRC_HOME not set\n" unless defined $ENV{'PHAROSIS_SRC_HOME'};
|
---|
[21205] | 32 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 33 | }
|
---|
[20983] | 34 |
|
---|
[21205] | 35 | use strict;
|
---|
| 36 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 37 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[20983] | 38 |
|
---|
| 39 |
|
---|
[21209] | 40 | use util;
|
---|
[21262] | 41 | use File::Basename;
|
---|
[21209] | 42 |
|
---|
[21205] | 43 | sub main
|
---|
| 44 | {
|
---|
| 45 |
|
---|
| 46 | my $ARGC = scalar(@ARGV);
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | if (($ARGC < 2) || ($ARGC>3)) {
|
---|
| 50 | my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
|
---|
| 51 | print STDERR "Usage: $progname collection file.jpg [doc-id]\n";
|
---|
| 52 | exit 1;
|
---|
| 53 | }
|
---|
[20983] | 54 |
|
---|
[21205] | 55 | # docid might be undefined, in which case later on is is derived from
|
---|
| 56 | # from col and the file-name tail to srcfilename
|
---|
| 57 | my ($col,$srcfilename,$docid) = @ARGV;
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | if ( ! -f $srcfilename ) {
|
---|
| 61 | print STDERR "Error: failed to find $srcfilename\n";
|
---|
| 62 | exit 1;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[21210] | 65 | if ( $srcfilename !~ m/\.je?pg$/i ) {
|
---|
[21211] | 66 | print STDERR "Error: Unrecognized JPEG filename extension\n";
|
---|
[21205] | 67 | exit 1;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | if (!defined $docid) {
|
---|
| 71 | my ($fileroot,$dirname_unused,$suffix_unused)
|
---|
| 72 | = fileparse($srcfilename, "\\.[^\\.]+\$");
|
---|
| 73 | $docid = $fileroot;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | # make sure file extension is lowercase .jpg
|
---|
| 77 |
|
---|
| 78 | my $dstfile = "$docid.jpg";
|
---|
| 79 |
|
---|
| 80 | if ( $col ne "" ) {
|
---|
| 81 | $dstfile="$col:$dstfile";
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | my $tmp_dir = &util::get_toplevel_tmp_dir();
|
---|
[21212] | 85 | $tmp_dir = &util::filename_cat($tmp_dir,"pharos-imageis");
|
---|
[21239] | 86 | if (! -d $tmp_dir) {
|
---|
| 87 | &util::mk_dir($tmp_dir);
|
---|
| 88 | }
|
---|
[21214] | 89 | my $dstfilename=&util::filename_cat($tmp_dir,$dstfile);
|
---|
[21205] | 90 |
|
---|
| 91 | &util::cp($srcfilename,$dstfilename);
|
---|
| 92 |
|
---|
| 93 | print "Generating add_file.xml\n";
|
---|
| 94 |
|
---|
| 95 | my $add_template_filename
|
---|
[21259] | 96 | = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"resources", "templates","add_file.xml");
|
---|
[21205] | 97 | my $add_this_filename = &util::filename_cat($tmp_dir,"add_file.xml");
|
---|
| 98 |
|
---|
| 99 | if (open(FIN,"<$add_template_filename")) {
|
---|
| 100 |
|
---|
| 101 | my $add_this_file_content = "";
|
---|
| 102 |
|
---|
| 103 | my $line;
|
---|
| 104 | while (defined ($line=<FIN>)) {
|
---|
[21214] | 105 | $line =~ s@\*\*imgfile\*\*@$dstfilename@g;
|
---|
[21205] | 106 |
|
---|
| 107 | $add_this_file_content .= $line;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | close(FIN);
|
---|
| 111 |
|
---|
| 112 | if (open(FOUT,">$add_this_filename")) {
|
---|
| 113 | print FOUT $add_this_file_content;
|
---|
| 114 | close(FOUT);
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | print STDERR "Error: failed to write out $add_this_filename\n";
|
---|
| 118 | print STDERR "$!\n";
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | else {
|
---|
| 122 | print STDERR "Error: failed to read $add_template_filename\n";
|
---|
| 123 | print STDERR "$!\n";
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
[21262] | 127 | my $jar_filename = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"pharos-imageis.jar");
|
---|
| 128 |
|
---|
[21298] | 129 |
|
---|
| 130 | my $prop_dir = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"classes");
|
---|
| 131 |
|
---|
| 132 | &util::envvar_append("CLASSPATH",$prop_dir);
|
---|
| 133 | &util::envvar_append("CLASSPATH",$jar_filename);
|
---|
| 134 |
|
---|
| 135 | my $java_cmd = "java imageis.ImageIS \"$add_this_filename\"";
|
---|
| 136 |
|
---|
| 137 |
|
---|
[21205] | 138 | print "Ingesting $dstfile\n";
|
---|
| 139 |
|
---|
| 140 | my $status = system($java_cmd);
|
---|
| 141 |
|
---|
| 142 | if ($status == 0 ) {
|
---|
[21269] | 143 | #&util::rm($add_this_filename);
|
---|
[21205] | 144 | }
|
---|
| 145 | else {
|
---|
| 146 | print STDERR "Error: Failed to run:\n";
|
---|
| 147 | print STDERR "$!\n";
|
---|
| 148 | exit 1;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[20983] | 152 |
|
---|
[21205] | 153 | main();
|
---|