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 (sort alphabetically @$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 ($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 | # sort files so they're built (and displayed) in alphabetical order
|
---|
70 | sub alphabetically {
|
---|
71 | open (A, &util::filename_cat($base_dir, $file, $a->[0])) ||
|
---|
72 | die "couldn't open " . &util::filename_cat($base_dir, $file, $a->[0]) . "\n";
|
---|
73 | open (B, &util::filename_cat($base_dir, $file, $b->[0])) ||
|
---|
74 | die "couldn't open " . &util::filename_cat($base_dir, $file, $b->[0]) . "\n";
|
---|
75 | my ($atitle, $btitle);
|
---|
76 | my $line = "";
|
---|
77 | while (defined ($line .= <A>)) {
|
---|
78 | if ($line =~ /Title=\"([^\"]*)\"/) {$atitle = $1; last;}
|
---|
79 | }
|
---|
80 | $line = "";
|
---|
81 | while (defined ($line .= <B>)) {
|
---|
82 | if ($line =~ /Title=\"([^\"]*)\"/) {$btitle = $1; last;}
|
---|
83 | }
|
---|
84 | close A;
|
---|
85 | close B;
|
---|
86 |
|
---|
87 | $atitle =~ tr/A-Z/a-z/;
|
---|
88 | $atitle =~ s/[^a-z0-9 ]//g;
|
---|
89 | $atitle =~ s/^\s+//;
|
---|
90 | $atitle =~ s/^(the|a|an)\b//;
|
---|
91 | $atitle =~ s/^\s+//;
|
---|
92 | $atitle =~ s/^(.).*$/$1/;
|
---|
93 |
|
---|
94 | $btitle =~ tr/A-Z/a-z/;
|
---|
95 | $btitle =~ s/[^a-z0-9 ]//g;
|
---|
96 | $btitle =~ s/^\s+//;
|
---|
97 | $btitle =~ s/^(the|a|an)\b//;
|
---|
98 | $btitle =~ s/^\s+//;
|
---|
99 | $btitle =~ s/^(.).*$/$1/;
|
---|
100 |
|
---|
101 | $atitle cmp $btitle;
|
---|
102 | }
|
---|
103 |
|
---|
104 | 1;
|
---|