[537] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[16013] | 3 | # ArchivesInfPlugin.pm --
|
---|
[537] | 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
[317] | 26 | # plugin which recurses through an archives.inf file
|
---|
| 27 | # (i.e. the file generated in the archives directory
|
---|
| 28 | # when an import is done), processing each file it finds
|
---|
[4] | 29 |
|
---|
[3540] | 30 | # 12-05-02 Added usage datastructure - John Thompson
|
---|
| 31 |
|
---|
[15870] | 32 | package ArchivesInfPlugin;
|
---|
[4] | 33 |
|
---|
| 34 | use util;
|
---|
[15870] | 35 | use AbstractPlugin;
|
---|
[4] | 36 | use plugin;
|
---|
| 37 | use arcinfo;
|
---|
[5680] | 38 | use gsprintf;
|
---|
[4] | 39 |
|
---|
[10254] | 40 | use strict;
|
---|
| 41 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 42 |
|
---|
[4] | 43 | BEGIN {
|
---|
[15870] | 44 | @ArchivesInfPlugin::ISA = ('AbstractPlugin');
|
---|
[4] | 45 | }
|
---|
| 46 |
|
---|
[10254] | 47 | my $arguments = [
|
---|
| 48 | ];
|
---|
| 49 |
|
---|
[15870] | 50 | my $options = { 'name' => "ArchivesInfPlugin",
|
---|
| 51 | 'desc' => "{ArchivesInfPlugin.desc}",
|
---|
[6408] | 52 | 'abstract' => "no",
|
---|
| 53 | 'inherits' => "yes" };
|
---|
[10254] | 54 |
|
---|
[5680] | 55 | sub gsprintf
|
---|
| 56 | {
|
---|
| 57 | return &gsprintf::gsprintf(@_);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[4] | 60 | sub new {
|
---|
[10218] | 61 | my ($class) = shift (@_);
|
---|
| 62 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 63 | push(@$pluginlist, $class);
|
---|
[4] | 64 |
|
---|
[15870] | 65 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 66 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10218] | 67 |
|
---|
[15870] | 68 | my $self = new AbstractPlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10218] | 69 |
|
---|
[4] | 70 | return bless $self, $class;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[10156] | 73 | sub deinit {
|
---|
| 74 | my ($self) = @_;
|
---|
| 75 |
|
---|
| 76 | my $archive_info = $self->{'archive_info'};
|
---|
| 77 |
|
---|
| 78 | if (defined $archive_info) {
|
---|
| 79 | my $archive_info_filename = $self->{'archive_info_filename'};
|
---|
| 80 |
|
---|
| 81 | my $file_list = $archive_info->get_file_list();
|
---|
| 82 |
|
---|
| 83 | # change each file to "Been Indexed"
|
---|
| 84 |
|
---|
| 85 | foreach my $subfile (@$file_list) {
|
---|
| 86 | my $doc_oid = $subfile->[1];
|
---|
[10254] | 87 | # why do we get this when it is not used???
|
---|
| 88 | my $index_status = $archive_info->get_status_info($doc_oid);
|
---|
[10156] | 89 | $archive_info->set_status_info($doc_oid,"B");
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | $archive_info->save_info($archive_info_filename);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[4] | 96 | # return 1 if this class might recurse using $pluginfo
|
---|
| 97 | sub is_recursive {
|
---|
| 98 | my $self = shift (@_);
|
---|
| 99 |
|
---|
| 100 | return 1;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[10156] | 103 |
|
---|
| 104 |
|
---|
| 105 |
|
---|
[317] | 106 | # return number of files processed, undef if can't process
|
---|
[4] | 107 | # Note that $base_dir might be "" and that $file might
|
---|
| 108 | # include directories
|
---|
| 109 | sub read {
|
---|
| 110 | my $self = shift (@_);
|
---|
[16392] | 111 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs,$total_count, $gli) = @_;
|
---|
[1424] | 112 | my $outhandle = $self->{'outhandle'};
|
---|
[4] | 113 |
|
---|
[317] | 114 | my $count = 0;
|
---|
| 115 |
|
---|
[4] | 116 | # see if this has a archives information file within it
|
---|
[1244] | 117 | my $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");
|
---|
[4] | 118 |
|
---|
| 119 | if (-e $archive_info_filename) {
|
---|
| 120 |
|
---|
[317] | 121 | # found an archives.inf file
|
---|
[15870] | 122 | &gsprintf($outhandle, "ArchivesInfPlugin: {common.processing} $archive_info_filename\n") if $self->{'verbosity'} > 1;
|
---|
[317] | 123 |
|
---|
[4] | 124 | # read in the archives information file
|
---|
| 125 | my $archive_info = new arcinfo ();
|
---|
[10156] | 126 | $self->{'archive_info'} = $archive_info;
|
---|
[12397] | 127 | $self->{'archive_info_filename'} = $archive_info_filename;
|
---|
[10156] | 128 |
|
---|
[4] | 129 | $archive_info->load_info ($archive_info_filename);
|
---|
| 130 |
|
---|
[230] | 131 | my $file_list = $archive_info->get_file_list();
|
---|
[4] | 132 |
|
---|
| 133 | # process each file
|
---|
[1244] | 134 | foreach my $subfile (@$file_list) {
|
---|
[9853] | 135 | last if ($maxdocs != -1 && ($total_count + $count) >= $maxdocs);
|
---|
[317] | 136 |
|
---|
[4] | 137 | my $tmp = &util::filename_cat ($file, $subfile->[0]);
|
---|
| 138 | next if $tmp eq $file;
|
---|
[16392] | 139 |
|
---|
[16257] | 140 | # We always process the file...
|
---|
| 141 | my $process_file = 1;
|
---|
[10156] | 142 |
|
---|
[16257] | 143 | # ...unless the build processor is incremental capable and -incremental was specified
|
---|
| 144 | if ($processor->is_incremental_capable() && $self->{'incremental'})
|
---|
| 145 | {
|
---|
| 146 | # We don't need to process the file if it has already been built
|
---|
| 147 | my $doc_oid = $subfile->[1];
|
---|
| 148 | my $index_status = $archive_info->get_status_info($doc_oid);
|
---|
| 149 | if ($index_status eq "B")
|
---|
| 150 | {
|
---|
| 151 | # Don't process this file
|
---|
| 152 | $process_file = 0;
|
---|
[10305] | 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | if ($process_file) {
|
---|
[10156] | 157 | # note: metadata is not carried on to the next level
|
---|
[16392] | 158 | $count += &plugin::read ($pluginfo, $base_dir, $tmp, $block_hash, {}, $processor, $maxdocs, ($total_count+$count), $gli);
|
---|
[10156] | 159 | }
|
---|
| 160 |
|
---|
[4] | 161 | }
|
---|
| 162 |
|
---|
[317] | 163 | return $count;
|
---|
[4] | 164 | }
|
---|
| 165 |
|
---|
| 166 | # wasn't an archives directory, someone else will have to process it
|
---|
[317] | 167 | return undef;
|
---|
[4] | 168 | }
|
---|
| 169 |
|
---|
| 170 | 1;
|
---|