#!/usr/bin/perl -w ########################################################################### # # pharos-imageis-add.pl -- # A component of the Greenstone digital library software # from the New Zealand Digital Library Project at the # University of Waikato, New Zealand. # # Copyright (C) 1999 New Zealand Digital Library Project # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ########################################################################### BEGIN { die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'}; die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'}; die "IMAGEISHOME not set\n" unless defined $ENV{'IMAGEISHOME'}; unshift (@INC, "$ENV{'GSDLHOME'}/perllib"); } use strict; no strict 'refs'; # allow filehandles to be variables and vice versa no strict 'subs'; # allow barewords (eg STDERR) as function arguments use util; sub main { my $ARGC = scalar(@ARGV); if (($ARGC < 2) || ($ARGC>3)) { my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/); print STDERR "Usage: $progname collection file.jpg [doc-id]\n"; exit 1; } # docid might be undefined, in which case later on is is derived from # from col and the file-name tail to srcfilename my ($col,$srcfilename,$docid) = @ARGV; if ( ! -f $srcfilename ) { print STDERR "Error: failed to find $srcfilename\n"; exit 1; } if ( $srcfilename !~ m/\.je?pg$/i ) { print STDERR "Error: Unrecognized JPEG filename extension\n"; exit 1; } if (!defined $docid) { my ($fileroot,$dirname_unused,$suffix_unused) = fileparse($srcfilename, "\\.[^\\.]+\$"); $docid = $fileroot; } # make sure file extension is lowercase .jpg my $dstfile = "$docid.jpg"; if ( $col ne "" ) { $dstfile="$col:$dstfile"; } my $tmp_dir = &util::get_toplevel_tmp_dir(); $tmp_dir = &util::filename_cat($tmp_dir,"pharos-imageis"); if (! -d $tmp_dir) { &util::mk_dir($tmp_dir); } my $dstfilename=&util::filename_cat($tmp_dir,$dstfile); &util::cp($srcfilename,$dstfilename); print "Generating add_file.xml\n"; my $add_template_filename = &util::filename_cat($ENV{'IMAGEISHOME'},"templates","add_file.xml"); my $add_this_filename = &util::filename_cat($tmp_dir,"add_file.xml"); if (open(FIN,"<$add_template_filename")) { my $add_this_file_content = ""; my $line; while (defined ($line=)) { $line =~ s@\*\*imgfile\*\*@$dstfilename@g; $add_this_file_content .= $line; } close(FIN); if (open(FOUT,">$add_this_filename")) { print FOUT $add_this_file_content; close(FOUT); } else { print STDERR "Error: failed to write out $add_this_filename\n"; print STDERR "$!\n"; } } else { print STDERR "Error: failed to read $add_template_filename\n"; print STDERR "$!\n"; } my $jar_filename = &util::filename_cat($ENV{'IMAGEISHOME'},"ImageIS.jar"); my $java_cmd = "java -jar \"$jar_filename\" \"$add_this_filename\""; #my $java_cmd = "java -cp /research/kjdon/home/pharos-greenstone3/ext/pharos/decompiled:/research/kjdon/home/pharos-greenstone3/ext/pharos/cmdline-api-srcpack/ImageIS.jar:/research/kjdon/home/pharos-greenstone3/ext/pharos MyImageIS $add_this_filename"; print "Ingesting $dstfile\n"; my $status = system($java_cmd); if ($status == 0 ) { &util::rm($add_this_filename); } else { print STDERR "Error: Failed to run:\n"; print STDERR "$!\n"; exit 1; } } main();