1 | # plugin which recurses through directories processing |
---|
2 | # each file it finds |
---|
3 | |
---|
4 | package ArcPlug; |
---|
5 | |
---|
6 | use util; |
---|
7 | use BasPlug; |
---|
8 | use plugin; |
---|
9 | use arcinfo; |
---|
10 | |
---|
11 | BEGIN { |
---|
12 | @ISA = ('BasPlug'); |
---|
13 | } |
---|
14 | |
---|
15 | sub new { |
---|
16 | my ($class) = @_; |
---|
17 | my $self = new BasPlug (); |
---|
18 | |
---|
19 | return bless $self, $class; |
---|
20 | } |
---|
21 | |
---|
22 | # return 1 if this class might recurse using $pluginfo |
---|
23 | sub is_recursive { |
---|
24 | my $self = shift (@_); |
---|
25 | |
---|
26 | return 1; |
---|
27 | } |
---|
28 | |
---|
29 | # return 1 if processed, 0 if not processed |
---|
30 | # Note that $base_dir might be "" and that $file might |
---|
31 | # include directories |
---|
32 | sub read { |
---|
33 | my $self = shift (@_); |
---|
34 | ($pluginfo, $base_dir, $file, $metadata, $processor) = @_; |
---|
35 | |
---|
36 | # see if this has a archives information file within it |
---|
37 | $archive_info_filename = &util::filename_cat($base_dir,$file,"archives.inf"); |
---|
38 | |
---|
39 | if (-e $archive_info_filename) { |
---|
40 | |
---|
41 | # read in the archives information file |
---|
42 | my $archive_info = new arcinfo (); |
---|
43 | $archive_info->load_info ($archive_info_filename); |
---|
44 | |
---|
45 | my $file_list = $archive_info->get_file_list(); |
---|
46 | |
---|
47 | # process each file |
---|
48 | foreach $subfile (@$file_list) { |
---|
49 | # note: metadata is not carried on to the next level |
---|
50 | my $tmp = &util::filename_cat ($file, $subfile->[0]); |
---|
51 | next if $tmp eq $file; |
---|
52 | &plugin::read ($pluginfo, $base_dir, $tmp, {}, $processor); |
---|
53 | } |
---|
54 | |
---|
55 | # all books have been processed so need to output classifications |
---|
56 | # to infodb - note that at present you have to import before building |
---|
57 | if (defined $processor->{'mode'} && $processor->{'mode'} eq 'infodb') { |
---|
58 | print STDERR "ArcPlug: Adding classifications to infodb\n"; |
---|
59 | $processor->process('classifications'); |
---|
60 | } |
---|
61 | |
---|
62 | return 1; |
---|
63 | } |
---|
64 | |
---|
65 | # wasn't an archives directory, someone else will have to process it |
---|
66 | return 0; |
---|
67 | } |
---|
68 | |
---|
69 | 1; |
---|