source: gsdl/trunk/perllib/plugins/ArchivesInfPlugin.pm@ 18469

Last change on this file since 18469 was 18469, checked in by davidb, 14 years ago

Support for reindexing a document added

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1###########################################################################
2#
3# ArchivesInfPlugin.pm --
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
26# plugin which reads through an archives.inf (or GDBM equivalent,
27# archiveinf-doc.{ldb,bdb} file (i.e. the file generated in the
28# archives directory when an import is done), processing each file it
29# finds
30
31package ArchivesInfPlugin;
32
33use util;
34use PrintInfo;
35use plugin;
36use arcinfo;
37use gsprintf;
38
39use strict;
40no strict 'refs'; # allow filehandles to be variables and viceversa
41
42BEGIN {
43 @ArchivesInfPlugin::ISA = ('PrintInfo');
44}
45
46my $arguments = [
47 ];
48
49my $options = { 'name' => "ArchivesInfPlugin",
50 'desc' => "{ArchivesInfPlugin.desc}",
51 'abstract' => "no",
52 'inherits' => "yes" };
53
54sub gsprintf
55{
56 return &gsprintf::gsprintf(@_);
57}
58
59sub new {
60 my ($class) = shift (@_);
61 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
62 push(@$pluginlist, $class);
63
64 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
65 push(@{$hashArgOptLists->{"OptList"}},$options);
66
67 my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
68
69 return bless $self, $class;
70}
71
72# called once, at the start of processing
73sub init {
74 my $self = shift (@_);
75 my ($verbosity, $outhandle, $failhandle) = @_;
76
77 # verbosity is passed through from the processor
78 $self->{'verbosity'} = $verbosity;
79
80 # as are the outhandle and failhandle
81 $self->{'outhandle'} = $outhandle if defined $outhandle;
82 $self->{'failhandle'} = $failhandle;
83
84}
85
86sub deinit {
87 my ($self) = @_;
88
89 my $archive_info = $self->{'archive_info'};
90
91 if (defined $archive_info) {
92 my $archive_info_filename = $self->{'archive_info_filename'};
93
94 my $file_list = $archive_info->get_file_list();
95
96 foreach my $subfile (@$file_list) {
97 my $doc_oid = $subfile->[1];
98
99 my $index_status = $archive_info->get_status_info($doc_oid);
100#### print STDERR "*** Away to Update $doc_oid $index_status\n";
101
102 if ($index_status eq "D") {
103 # delete
104 $archive_info->delete_info($doc_oid);
105 &GDBMUtils::gdbmDatabaseRemove($archive_info_filename,$doc_oid);
106 }
107 elsif ($index_status =~ m/^(I|R)$/) {
108 # mark as "been indexed"
109 $archive_info->set_status_info($doc_oid,"B");
110 }
111 }
112
113 $archive_info->save_info($archive_info_filename);
114 }
115}
116
117# called at the beginning of each plugin pass (import has one, buildin has many)
118sub begin {
119 my $self = shift (@_);
120 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
121
122}
123
124# called at the end of each plugin pass
125sub end {
126 my ($self) = shift (@_);
127
128}
129
130# called if we are doing incremental building
131sub set_incremental {
132 my $self = shift(@_);
133 my ($incremental) = @_;
134
135 $self->{'incremental'} = $incremental;
136}
137
138# return 1 if this class might recurse using $pluginfo
139sub is_recursive {
140 my $self = shift (@_);
141
142 return 1;
143}
144
145
146sub compile_stats {
147 my $self = shift(@_);
148 my ($stats) = @_;
149}
150
151# We don't do metadata_read
152sub metadata_read {
153 my $self = shift (@_);
154 my ($pluginfo, $base_dir, $file, $block_hash, $extrametakeys, $extrametadata, $processor, $maxdocs, $gli) = @_;
155
156 return undef;
157}
158
159# we don't do any file blocking
160sub file_block_read {
161
162 my $self = shift (@_);
163 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
164
165 return undef;
166}
167
168
169# return number of files processed, undef if can't process
170# Note that $base_dir might be "" and that $file might
171# include directories
172sub read {
173 my $self = shift (@_);
174 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs,$total_count, $gli) = @_;
175 my $outhandle = $self->{'outhandle'};
176
177 my $count = 0;
178
179 # see if this has a archives information file within it
180## my $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");
181 my $db_ext = &util::is_little_endian() ? ".ldb" : ".bdb";
182 my $doc_db = "archiveinf-doc$db_ext";
183 my $archive_info_filename = &util::filename_cat($base_dir,$file,$doc_db);
184
185 if (-e $archive_info_filename) {
186
187 # found an archives.inf file
188 &gsprintf($outhandle, "ArchivesInfPlugin: {common.processing} $archive_info_filename\n") if $self->{'verbosity'} > 1;
189
190 # read in the archives information file
191 my $archive_info = new arcinfo ();
192 $self->{'archive_info'} = $archive_info;
193 $self->{'archive_info_filename'} = $archive_info_filename;
194
195 $archive_info->load_info ($archive_info_filename);
196
197 my $file_list = $archive_info->get_file_list();
198
199 # process each file
200 foreach my $subfile (@$file_list) {
201
202 last if ($maxdocs != -1 && ($total_count + $count) >= $maxdocs);
203
204 my $tmp = &util::filename_cat ($file, $subfile->[0]);
205 next if $tmp eq $file;
206
207 my $doc_oid = $subfile->[1];
208 my $index_status = $archive_info->get_status_info($doc_oid);
209
210 my $curr_mode = $processor->get_mode();
211 my $new_mode = $curr_mode;
212
213 # Start by assuming we want to process the file...
214 my $process_file = 1;
215
216 # ...unless the build processor is incremental capable and -incremental was specified, in which case we need to check its index_status flag
217 if ($processor->is_incremental_capable() && $self->{'incremental'})
218 {
219 # Check to see if the file needs indexing
220 if ($index_status eq "B")
221 {
222 # Don't process this file as it has already been indexed
223 $process_file = 0;
224 }
225 elsif ($index_status eq "D") {
226 # Need to be delete it from the index.
227 $new_mode = $curr_mode."delete";
228 $process_file = 1;
229 }
230 elsif ($index_status eq "R") {
231 # Need to be reindexed/replaced
232 $new_mode = $curr_mode."reindex";
233
234 $process_file = 1;
235 }
236 }
237 # ... or we're being asked to delete it (in which case skip it)
238 elsif ($index_status eq "D") {
239 # Non-incremental Delete
240 # It's already been deleted from the archives directory
241 # (done during import.pl)
242 # => All we need to do here is not process it
243
244 $process_file = 0;
245 }
246
247 if (!$processor->is_incremental_capable() && $self->{'incremental'}) {
248 # Nag feature
249 if (!defined $self->{'incremental-warning'}) {
250 print $outhandle "\n";
251 print $outhandle "Warning: command-line option '-incremental' used with *non-incremental*\n";
252 print $outhandle " processor '", ref $processor, "'. Some conflicts may arise.\n";
253 print $outhandle "\n";
254 sleep 10;
255 $self->{'incremental-warning'} = 1;
256 }
257 }
258
259
260
261 if ($process_file) {
262 # note: metadata is not carried on to the next level
263
264 $processor->set_mode($new_mode) if ($new_mode ne $curr_mode);
265
266 $count += &plugin::read ($pluginfo, $base_dir, $tmp, $block_hash, {}, $processor, $maxdocs, ($total_count+$count), $gli);
267
268 $processor->set_mode($curr_mode) if ($new_mode ne $curr_mode);
269 }
270 }
271
272 return $count;
273 }
274
275 # wasn't an archives directory, someone else will have to process it
276 return undef;
277}
278
2791;
Note: See TracBrowser for help on using the repository browser.