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

Last change on this file since 21340 was 21340, checked in by kjdon, 14 years ago

corrected jpg regex

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_SRC_HOME not set\n" unless defined $ENV{'PHAROSIS_SRC_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;
41use File::Basename;
42
43sub 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 }
54
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
65 if ( $srcfilename !~ m/\.jpe?g$/i ) {
66 print STDERR "Error: Unrecognized JPEG filename extension\n";
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();
85 $tmp_dir = &util::filename_cat($tmp_dir,"pharos-imageis");
86 if (! -d $tmp_dir) {
87 &util::mk_all_dir($tmp_dir);
88 }
89 my $dstfilename=&util::filename_cat($tmp_dir,$dstfile);
90
91 &util::cp($srcfilename,$dstfilename);
92
93 print "Generating add_file.xml\n";
94
95 my $add_template_filename
96 = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"resources", "templates","add_file.xml");
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>)) {
105 $line =~ s@\*\*imgfile\*\*@$dstfilename@g;
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
127 my $jar_filename = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"pharos-imageis.jar");
128
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
138 print "Ingesting $dstfile\n";
139
140 my $status = system($java_cmd);
141
142 if ($status == 0 ) {
143 #&util::rm($add_this_filename);
144 }
145 else {
146 print STDERR "Error: Failed to run:\n";
147 print STDERR "$!\n";
148 exit 1;
149 }
150}
151
152
153main();
Note: See TracBrowser for help on using the repository browser.