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

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

Modifications for incremental building to support files that need to be deleted

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 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 print STDERR "*** Running ArchivesInf deinit\n";
90
91 my $archive_info = $self->{'archive_info'};
92
93 if (defined $archive_info) {
94 my $archive_info_filename = $self->{'archive_info_filename'};
95
96 my $file_list = $archive_info->get_file_list();
97
98 foreach my $subfile (@$file_list) {
99 my $doc_oid = $subfile->[1];
100
101 my $index_status = $archive_info->get_status_info($doc_oid);
102 if ($index_status eq "D") {
103 # delete
104 $archive_info->delete_info($doc_oid);
105 }
106 elsif ($index_status =~ m/^(I|R)$/) {
107 # mark as "been indexed"
108 $archive_info->set_status_info($doc_oid,"B");
109 }
110 }
111
112 $archive_info->save_info($archive_info_filename);
113 }
114}
115
116# called at the beginning of each plugin pass (import has one, buildin has many)
117sub begin {
118 my $self = shift (@_);
119 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
120
121}
122
123# called at the end of each plugin pass
124sub end {
125 my ($self) = shift (@_);
126
127}
128
129# called if we are doing incremental building
130sub set_incremental {
131 my $self = shift(@_);
132 my ($incremental) = @_;
133
134 $self->{'incremental'} = $incremental;
135}
136
137# return 1 if this class might recurse using $pluginfo
138sub is_recursive {
139 my $self = shift (@_);
140
141 return 1;
142}
143
144
145sub compile_stats {
146 my $self = shift(@_);
147 my ($stats) = @_;
148}
149
150# We don't do metadata_read
151sub metadata_read {
152 my $self = shift (@_);
153 my ($pluginfo, $base_dir, $file, $block_hash, $extrametakeys, $extrametadata, $processor, $maxdocs, $gli) = @_;
154
155 return undef;
156}
157
158# we don't do any file blocking
159sub file_block_read {
160
161 my $self = shift (@_);
162 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
163
164 return undef;
165}
166
167
168# return number of files processed, undef if can't process
169# Note that $base_dir might be "" and that $file might
170# include directories
171sub read {
172 my $self = shift (@_);
173 my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs,$total_count, $gli) = @_;
174 my $outhandle = $self->{'outhandle'};
175
176 my $count = 0;
177
178 # see if this has a archives information file within it
179## my $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");
180 my $db_ext = &util::is_little_endian() ? ".ldb" : ".bdb";
181 my $doc_db = "archiveinf-doc$db_ext";
182 my $archive_info_filename = &util::filename_cat($base_dir,$file,$doc_db);
183
184 if (-e $archive_info_filename) {
185
186 # found an archives.inf file
187 &gsprintf($outhandle, "ArchivesInfPlugin: {common.processing} $archive_info_filename\n") if $self->{'verbosity'} > 1;
188
189 # read in the archives information file
190 my $archive_info = new arcinfo ();
191 $self->{'archive_info'} = $archive_info;
192 $self->{'archive_info_filename'} = $archive_info_filename;
193
194 $archive_info->load_info ($archive_info_filename);
195
196 my $file_list = $archive_info->get_file_list();
197
198 # process each file
199 foreach my $subfile (@$file_list) {
200
201 last if ($maxdocs != -1 && ($total_count + $count) >= $maxdocs);
202
203 my $tmp = &util::filename_cat ($file, $subfile->[0]);
204 next if $tmp eq $file;
205
206 # We always process the file...
207 my $process_file = 1;
208
209 # ...unless the build processor is incremental capable and -incremental was specified
210 if ($processor->is_incremental_capable() && $self->{'incremental'})
211 {
212 # Check to see if the file needs indexing
213 my $doc_oid = $subfile->[1];
214 my $index_status = $archive_info->get_status_info($doc_oid);
215 if ($index_status eq "B")
216 {
217 # Don't process this file as it has already been indexed
218 $process_file = 0;
219 }
220 }
221
222 if ($process_file) {
223 # note: metadata is not carried on to the next level
224 $count += &plugin::read ($pluginfo, $base_dir, $tmp, $block_hash, {}, $processor, $maxdocs, ($total_count+$count), $gli);
225 }
226
227 }
228
229 return $count;
230 }
231
232 # wasn't an archives directory, someone else will have to process it
233 return undef;
234}
235
2361;
Note: See TracBrowser for help on using the repository browser.