[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 |
|
---|
[18441] | 26 | # plugin which reads through an archives.inf (or GDBM equivalent,
|
---|
[18659] | 27 | # archiveinf-doc.gdb file (i.e. the file generated in the
|
---|
[18441] | 28 | # archives directory when an import is done), processing each file it
|
---|
| 29 | # finds
|
---|
[4] | 30 |
|
---|
[15870] | 31 | package ArchivesInfPlugin;
|
---|
[4] | 32 |
|
---|
| 33 | use util;
|
---|
[18528] | 34 | use doc;
|
---|
[17738] | 35 | use PrintInfo;
|
---|
[4] | 36 | use plugin;
|
---|
| 37 | use arcinfo;
|
---|
[5680] | 38 | use gsprintf;
|
---|
[19759] | 39 | use GDBMUtils;
|
---|
[4] | 40 |
|
---|
[10254] | 41 | use strict;
|
---|
| 42 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 43 |
|
---|
[4] | 44 | BEGIN {
|
---|
[17738] | 45 | @ArchivesInfPlugin::ISA = ('PrintInfo');
|
---|
[4] | 46 | }
|
---|
| 47 |
|
---|
[10254] | 48 | my $arguments = [
|
---|
| 49 | ];
|
---|
| 50 |
|
---|
[15870] | 51 | my $options = { 'name' => "ArchivesInfPlugin",
|
---|
| 52 | 'desc' => "{ArchivesInfPlugin.desc}",
|
---|
[6408] | 53 | 'abstract' => "no",
|
---|
| 54 | 'inherits' => "yes" };
|
---|
[10254] | 55 |
|
---|
[5680] | 56 | sub gsprintf
|
---|
| 57 | {
|
---|
| 58 | return &gsprintf::gsprintf(@_);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[4] | 61 | sub new {
|
---|
[10218] | 62 | my ($class) = shift (@_);
|
---|
| 63 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 64 | push(@$pluginlist, $class);
|
---|
[4] | 65 |
|
---|
[15870] | 66 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 67 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10218] | 68 |
|
---|
[17738] | 69 | my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10218] | 70 |
|
---|
[4] | 71 | return bless $self, $class;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[17738] | 74 | # called once, at the start of processing
|
---|
| 75 | sub 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 |
|
---|
[10156] | 88 | sub deinit {
|
---|
| 89 | my ($self) = @_;
|
---|
| 90 |
|
---|
| 91 | my $archive_info = $self->{'archive_info'};
|
---|
[18508] | 92 | my $verbosity = $self->{'verbosity'};
|
---|
| 93 | my $outhandle = $self->{'outhandle'};
|
---|
[10156] | 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 |
|
---|
[18456] | 100 | foreach my $subfile (@$file_list) {
|
---|
[10156] | 101 | my $doc_oid = $subfile->[1];
|
---|
[18441] | 102 |
|
---|
[10254] | 103 | my $index_status = $archive_info->get_status_info($doc_oid);
|
---|
[18456] | 104 |
|
---|
[18441] | 105 | if ($index_status eq "D") {
|
---|
| 106 | # delete
|
---|
| 107 | $archive_info->delete_info($doc_oid);
|
---|
[18469] | 108 | &GDBMUtils::gdbmDatabaseRemove($archive_info_filename,$doc_oid);
|
---|
[18508] | 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 |
|
---|
[18509] | 118 | print $outhandle "Removing $doc_dirname\n" if ($verbosity>2);
|
---|
[18508] | 119 |
|
---|
| 120 | &util::rm_r($doc_dirname);
|
---|
| 121 |
|
---|
| 122 |
|
---|
[18441] | 123 | }
|
---|
| 124 | elsif ($index_status =~ m/^(I|R)$/) {
|
---|
| 125 | # mark as "been indexed"
|
---|
| 126 | $archive_info->set_status_info($doc_oid,"B");
|
---|
| 127 | }
|
---|
[10156] | 128 | }
|
---|
| 129 |
|
---|
| 130 | $archive_info->save_info($archive_info_filename);
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[17738] | 134 | # called at the beginning of each plugin pass (import has one, buildin has many)
|
---|
| 135 | sub begin {
|
---|
| 136 | my $self = shift (@_);
|
---|
| 137 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 138 |
|
---|
[18508] | 139 | $self->{'base_dir'} = $base_dir;
|
---|
[17738] | 140 | }
|
---|
| 141 |
|
---|
| 142 | # called at the end of each plugin pass
|
---|
| 143 | sub end {
|
---|
| 144 | my ($self) = shift (@_);
|
---|
| 145 |
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
[4] | 149 | # return 1 if this class might recurse using $pluginfo
|
---|
| 150 | sub is_recursive {
|
---|
| 151 | my $self = shift (@_);
|
---|
| 152 |
|
---|
| 153 | return 1;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[10156] | 156 |
|
---|
[17738] | 157 | sub compile_stats {
|
---|
| 158 | my $self = shift(@_);
|
---|
| 159 | my ($stats) = @_;
|
---|
| 160 | }
|
---|
[10156] | 161 |
|
---|
[17738] | 162 | # We don't do metadata_read
|
---|
| 163 | sub metadata_read {
|
---|
| 164 | my $self = shift (@_);
|
---|
[19493] | 165 | my ($pluginfo, $base_dir, $file, $block_hash,
|
---|
| 166 | $extrametakeys, $extrametadata, $extrametafile,
|
---|
| 167 | $processor, $maxdocs, $gli) = @_;
|
---|
[10156] | 168 |
|
---|
[17738] | 169 | return undef;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | sub file_block_read {
|
---|
| 173 |
|
---|
| 174 | my $self = shift (@_);
|
---|
| 175 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
|
---|
| 176 |
|
---|
[18528] | 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 |
|
---|
[17738] | 186 | return undef;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
[317] | 190 | # return number of files processed, undef if can't process
|
---|
[4] | 191 | # Note that $base_dir might be "" and that $file might
|
---|
| 192 | # include directories
|
---|
| 193 | sub read {
|
---|
| 194 | my $self = shift (@_);
|
---|
[16392] | 195 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs,$total_count, $gli) = @_;
|
---|
[1424] | 196 | my $outhandle = $self->{'outhandle'};
|
---|
[4] | 197 |
|
---|
[317] | 198 | my $count = 0;
|
---|
| 199 |
|
---|
[4] | 200 | # see if this has a archives information file within it
|
---|
[18441] | 201 | ## my $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf");
|
---|
[18659] | 202 |
|
---|
| 203 | my $doc_db = "archiveinf-doc.gdb";
|
---|
[18441] | 204 | my $archive_info_filename = &util::filename_cat($base_dir,$file,$doc_db);
|
---|
[4] | 205 |
|
---|
| 206 | if (-e $archive_info_filename) {
|
---|
| 207 |
|
---|
[317] | 208 | # found an archives.inf file
|
---|
[15870] | 209 | &gsprintf($outhandle, "ArchivesInfPlugin: {common.processing} $archive_info_filename\n") if $self->{'verbosity'} > 1;
|
---|
[317] | 210 |
|
---|
[4] | 211 | # read in the archives information file
|
---|
| 212 | my $archive_info = new arcinfo ();
|
---|
[10156] | 213 | $self->{'archive_info'} = $archive_info;
|
---|
[12397] | 214 | $self->{'archive_info_filename'} = $archive_info_filename;
|
---|
[10156] | 215 |
|
---|
[4] | 216 | $archive_info->load_info ($archive_info_filename);
|
---|
| 217 |
|
---|
[230] | 218 | my $file_list = $archive_info->get_file_list();
|
---|
[4] | 219 |
|
---|
| 220 | # process each file
|
---|
[1244] | 221 | foreach my $subfile (@$file_list) {
|
---|
[18441] | 222 |
|
---|
[9853] | 223 | last if ($maxdocs != -1 && ($total_count + $count) >= $maxdocs);
|
---|
[317] | 224 |
|
---|
[4] | 225 | my $tmp = &util::filename_cat ($file, $subfile->[0]);
|
---|
| 226 | next if $tmp eq $file;
|
---|
[18456] | 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...
|
---|
[16257] | 235 | my $process_file = 1;
|
---|
[10156] | 236 |
|
---|
[18469] | 237 | # ...unless the build processor is incremental capable and -incremental was specified, in which case we need to check its index_status flag
|
---|
[16257] | 238 | if ($processor->is_incremental_capable() && $self->{'incremental'})
|
---|
| 239 | {
|
---|
[18441] | 240 | # Check to see if the file needs indexing
|
---|
[16257] | 241 | if ($index_status eq "B")
|
---|
| 242 | {
|
---|
[18441] | 243 | # Don't process this file as it has already been indexed
|
---|
[16257] | 244 | $process_file = 0;
|
---|
[10305] | 245 | }
|
---|
[18456] | 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") {
|
---|
[18469] | 252 | # Need to be reindexed/replaced
|
---|
[18456] | 253 | $new_mode = $curr_mode."reindex";
|
---|
[18469] | 254 |
|
---|
[18456] | 255 | $process_file = 1;
|
---|
| 256 | }
|
---|
[10305] | 257 | }
|
---|
[18456] | 258 | # ... or we're being asked to delete it (in which case skip it)
|
---|
| 259 | elsif ($index_status eq "D") {
|
---|
[18469] | 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
|
---|
[10305] | 264 |
|
---|
[18456] | 265 | $process_file = 0;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[18469] | 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 |
|
---|
[10305] | 280 | if ($process_file) {
|
---|
[10156] | 281 | # note: metadata is not carried on to the next level
|
---|
[18456] | 282 |
|
---|
| 283 | $processor->set_mode($new_mode) if ($new_mode ne $curr_mode);
|
---|
| 284 |
|
---|
[16392] | 285 | $count += &plugin::read ($pluginfo, $base_dir, $tmp, $block_hash, {}, $processor, $maxdocs, ($total_count+$count), $gli);
|
---|
[18456] | 286 |
|
---|
| 287 | $processor->set_mode($curr_mode) if ($new_mode ne $curr_mode);
|
---|
[10156] | 288 | }
|
---|
[4] | 289 | }
|
---|
| 290 |
|
---|
[317] | 291 | return $count;
|
---|
[4] | 292 | }
|
---|
| 293 |
|
---|
[18528] | 294 |
|
---|
[4] | 295 | # wasn't an archives directory, someone else will have to process it
|
---|
[317] | 296 | return undef;
|
---|
[4] | 297 | }
|
---|
| 298 |
|
---|
| 299 | 1;
|
---|