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

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

Missing use statement to include GDBMUtils.pm

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 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# called if we are doing incremental building
149sub set_incremental {
150 my $self = shift(@_);
151 my ($incremental) = @_;
152
153 $self->{'incremental'} = $incremental;
154}
155
156# return 1 if this class might recurse using $pluginfo
157sub is_recursive {
158 my $self = shift (@_);
159
160 return 1;
161}
162
163
164sub compile_stats {
165 my $self = shift(@_);
166 my ($stats) = @_;
167}
168
169# We don't do metadata_read
170sub metadata_read {
171 my $self = shift (@_);
172 my ($pluginfo, $base_dir, $file, $block_hash,
173 $extrametakeys, $extrametadata, $extrametafile,
174 $processor, $maxdocs, $gli) = @_;
175
176 return undef;
177}
178
179sub file_block_read {
180
181 my $self = shift (@_);
182 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
183
184 if ($file eq "OIDcount") {
185 my ($filename_full_path, $filename_no_path)
186 = &util::get_full_filenames($base_dir, $file);
187 $block_hash->{'file_blocks'}->{$filename_full_path} = 1;
188 return 1;
189 }
190
191 # otherwise, we don't do any file blocking
192
193 return undef;
194}
195
196
197# return number of files processed, undef if can't process
198# Note that $base_dir might be "" and that $file might
199# include directories
200sub read {
201 my $self = shift (@_);
202 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs,$total_count, $gli) = @_;
203 my $outhandle = $self->{'outhandle'};
204
205 my $count = 0;
206
207 # see if this has a archives information file within it
208## my $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");
209
210 my $doc_db = "archiveinf-doc.gdb";
211 my $archive_info_filename = &util::filename_cat($base_dir,$file,$doc_db);
212
213 if (-e $archive_info_filename) {
214
215 # found an archives.inf file
216 &gsprintf($outhandle, "ArchivesInfPlugin: {common.processing} $archive_info_filename\n") if $self->{'verbosity'} > 1;
217
218 # read in the archives information file
219 my $archive_info = new arcinfo ();
220 $self->{'archive_info'} = $archive_info;
221 $self->{'archive_info_filename'} = $archive_info_filename;
222
223 $archive_info->load_info ($archive_info_filename);
224
225 my $file_list = $archive_info->get_file_list();
226
227 # process each file
228 foreach my $subfile (@$file_list) {
229
230 last if ($maxdocs != -1 && ($total_count + $count) >= $maxdocs);
231
232 my $tmp = &util::filename_cat ($file, $subfile->[0]);
233 next if $tmp eq $file;
234
235 my $doc_oid = $subfile->[1];
236 my $index_status = $archive_info->get_status_info($doc_oid);
237
238 my $curr_mode = $processor->get_mode();
239 my $new_mode = $curr_mode;
240
241 # Start by assuming we want to process the file...
242 my $process_file = 1;
243
244 # ...unless the build processor is incremental capable and -incremental was specified, in which case we need to check its index_status flag
245 if ($processor->is_incremental_capable() && $self->{'incremental'})
246 {
247 # Check to see if the file needs indexing
248 if ($index_status eq "B")
249 {
250 # Don't process this file as it has already been indexed
251 $process_file = 0;
252 }
253 elsif ($index_status eq "D") {
254 # Need to be delete it from the index.
255 $new_mode = $curr_mode."delete";
256 $process_file = 1;
257 }
258 elsif ($index_status eq "R") {
259 # Need to be reindexed/replaced
260 $new_mode = $curr_mode."reindex";
261
262 $process_file = 1;
263 }
264 }
265 # ... or we're being asked to delete it (in which case skip it)
266 elsif ($index_status eq "D") {
267 # Non-incremental Delete
268 # It's already been deleted from the archives directory
269 # (done during import.pl)
270 # => All we need to do here is not process it
271
272 $process_file = 0;
273 }
274
275 if (!$processor->is_incremental_capable() && $self->{'incremental'}) {
276 # Nag feature
277 if (!defined $self->{'incremental-warning'}) {
278 print $outhandle "\n";
279 print $outhandle "Warning: command-line option '-incremental' used with *non-incremental*\n";
280 print $outhandle " processor '", ref $processor, "'. Some conflicts may arise.\n";
281 print $outhandle "\n";
282 sleep 10;
283 $self->{'incremental-warning'} = 1;
284 }
285 }
286
287 if ($process_file) {
288 # note: metadata is not carried on to the next level
289
290 $processor->set_mode($new_mode) if ($new_mode ne $curr_mode);
291
292 $count += &plugin::read ($pluginfo, $base_dir, $tmp, $block_hash, {}, $processor, $maxdocs, ($total_count+$count), $gli);
293
294 $processor->set_mode($curr_mode) if ($new_mode ne $curr_mode);
295 }
296 }
297
298 return $count;
299 }
300
301
302 # wasn't an archives directory, someone else will have to process it
303 return undef;
304}
305
3061;
Note: See TracBrowser for help on using the repository browser.