source: gs3-extensions/pharos/trunk/bin/script/pharos-imageis-add.pl@ 21255

Last change on this file since 21255 was 21255, checked in by davidb, 11 years ago

switch from etc/templates to resources/templates

File size: 4.1 KB
Line 
1#!/usr/bin/perl -w
2
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###########################################################################
27
28BEGIN {
29 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
30 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
31 die "PHAROSIS_HOME not set\n" unless defined $ENV{'PHAROSIS_HOME'};
32 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
33}
34
35use strict;
36no strict 'refs'; # allow filehandles to be variables and vice versa
37no strict 'subs'; # allow barewords (eg STDERR) as function arguments
38
39
40use util;
41
42sub main
43{
44
45 my $ARGC = scalar(@ARGV);
46
47
48 if (($ARGC < 2) || ($ARGC>3)) {
49 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
50 print STDERR "Usage: $progname collection file.jpg [doc-id]\n";
51 exit 1;
52 }
53
54 # docid might be undefined, in which case later on is is derived from
55 # from col and the file-name tail to srcfilename
56 my ($col,$srcfilename,$docid) = @ARGV;
57
58
59 if ( ! -f $srcfilename ) {
60 print STDERR "Error: failed to find $srcfilename\n";
61 exit 1;
62 }
63
64 if ( $srcfilename !~ m/\.je?pg$/i ) {
65 print STDERR "Error: Unrecognized JPEG filename extension\n";
66 exit 1;
67 }
68
69 if (!defined $docid) {
70 my ($fileroot,$dirname_unused,$suffix_unused)
71 = fileparse($srcfilename, "\\.[^\\.]+\$");
72 $docid = $fileroot;
73 }
74
75 # make sure file extension is lowercase .jpg
76
77 my $dstfile = "$docid.jpg";
78
79 if ( $col ne "" ) {
80 $dstfile="$col:$dstfile";
81 }
82
83 my $tmp_dir = &util::get_toplevel_tmp_dir();
84 $tmp_dir = &util::filename_cat($tmp_dir,"pharos-imageis");
85 if (! -d $tmp_dir) {
86 &util::mk_dir($tmp_dir);
87 }
88 my $dstfilename=&util::filename_cat($tmp_dir,$dstfile);
89
90 &util::cp($srcfilename,$dstfilename);
91
92 print "Generating add_file.xml\n";
93
94 my $add_template_filename
95 = &util::filename_cat($ENV{'PHAROSIS_HOME'},"resources", "templates","add_file.xml");
96 my $add_this_filename = &util::filename_cat($tmp_dir,"add_file.xml");
97
98 if (open(FIN,"<$add_template_filename")) {
99
100 my $add_this_file_content = "";
101
102 my $line;
103 while (defined ($line=<FIN>)) {
104 $line =~ s@\*\*imgfile\*\*@$dstfilename@g;
105
106 $add_this_file_content .= $line;
107 }
108
109 close(FIN);
110
111 if (open(FOUT,">$add_this_filename")) {
112 print FOUT $add_this_file_content;
113 close(FOUT);
114 }
115 else {
116 print STDERR "Error: failed to write out $add_this_filename\n";
117 print STDERR "$!\n";
118 }
119 }
120 else {
121 print STDERR "Error: failed to read $add_template_filename\n";
122 print STDERR "$!\n";
123 }
124
125
126 my $jar_filename = &util::filename_cat($ENV{'PHAROSIS_HOME'},"ImageIS.jar");
127 my $java_cmd = "java -jar \"$jar_filename\" \"$add_this_filename\"";
128 #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";
129 print "Ingesting $dstfile\n";
130
131 my $status = system($java_cmd);
132
133 if ($status == 0 ) {
134 &util::rm($add_this_filename);
135 }
136 else {
137 print STDERR "Error: Failed to run:\n";
138 print STDERR "$!\n";
139 exit 1;
140 }
141}
142
143
144main();
Note: See TracBrowser for help on using the repository browser.