[21205] | 1 | #!/usr/bin/perl -w
|
---|
[20983] | 2 |
|
---|
[21205] | 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # pharos-imageis-delete.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 |
|
---|
| 35 |
|
---|
[21205] | 36 | use strict;
|
---|
| 37 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 38 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[20983] | 39 |
|
---|
[21209] | 40 | use util;
|
---|
[20983] | 41 |
|
---|
[21209] | 42 |
|
---|
[21205] | 43 | sub main
|
---|
| 44 | {
|
---|
| 45 |
|
---|
| 46 | my $ARGC = scalar(@ARGV);
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | if ($ARGC != 2) {
|
---|
| 50 | my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
|
---|
| 51 | print STDERR "Usage: $progname collection doc-id\n";
|
---|
| 52 | exit 1;
|
---|
| 53 | }
|
---|
[20983] | 54 |
|
---|
[21205] | 55 | my ($col,$id) = @ARGV;
|
---|
| 56 |
|
---|
| 57 | my $docid = $id;
|
---|
| 58 | if ( $col ne "" ) {
|
---|
| 59 | $docid="$col:$docid";
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | my $tmp_dir = &util::get_toplevel_tmp_dir();
|
---|
[21212] | 63 | $tmp_dir = &util::filename_cat($tmp_dir,"pharos-imageis");
|
---|
| 64 |
|
---|
[21205] | 65 | print "Generating del_id.xml\n";
|
---|
| 66 |
|
---|
| 67 | my $del_template_filename
|
---|
[21259] | 68 | = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"resources", "templates","del_id.xml");
|
---|
[21205] | 69 | my $del_this_filename = &util::filename_cat($tmp_dir,"del_id.xml");
|
---|
| 70 |
|
---|
| 71 | if (open(FIN,"<$del_template_filename")) {
|
---|
| 72 |
|
---|
| 73 | my $del_this_file_content = "";
|
---|
| 74 |
|
---|
| 75 | my $line;
|
---|
| 76 | while (defined ($line=<FIN>)) {
|
---|
| 77 | $line =~ s@\*\*docid\*\*@$docid@g;
|
---|
| 78 |
|
---|
| 79 | $del_this_file_content .= $line;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | close(FIN);
|
---|
| 83 |
|
---|
| 84 | if (open(FOUT,">$del_this_filename")) {
|
---|
| 85 | print FOUT $del_this_file_content;
|
---|
| 86 | close(FOUT);
|
---|
| 87 | }
|
---|
| 88 | else {
|
---|
| 89 | print STDERR "Error: failed to write out $del_this_filename\n";
|
---|
| 90 | print STDERR "$!\n";
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | else {
|
---|
| 94 | print STDERR "Error: failed to read $del_template_filename\n";
|
---|
| 95 | print STDERR "$!\n";
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
[21259] | 99 | my $jar_filename = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"ImageIS.jar");
|
---|
[21298] | 100 | my $prop_dir = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"classes");
|
---|
[20983] | 101 |
|
---|
[21298] | 102 | &util::envvar_append("CLASSPATH",$prop_dir);
|
---|
| 103 | &util::envvar_append("CLASSPATH",$jar_filename);
|
---|
| 104 |
|
---|
| 105 | my $java_cmd = "java imageis.ImageIS \"$del_this_filename\"";
|
---|
| 106 |
|
---|
[21205] | 107 | print "Deleting $docid\n";
|
---|
| 108 |
|
---|
| 109 | my $status = system($java_cmd);
|
---|
| 110 |
|
---|
| 111 | if ($status == 0 ) {
|
---|
| 112 | &util::rm($del_this_filename);
|
---|
| 113 | }
|
---|
| 114 | else {
|
---|
| 115 | print STDERR "Error: Failed to run:\n";
|
---|
| 116 | print STDERR "$!\n";
|
---|
| 117 | exit 1;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | main();
|
---|
| 123 |
|
---|