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