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

Last change on this file since 20577 was 20577, checked in by davidb, 15 years ago

Changes to support new incremental_mode variable, and to track metadata.xml files more closely so incremental building works when a document is first build without any metadata attached, then then in a subsequent build has metadata from such a source as metadata.xml added.

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