Changeset 13310 for trunk/niupepa


Ignore:
Timestamp:
2006-11-20T17:08:03+13:00 (17 years ago)
Author:
nzdl
Message:

modify the new method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/niupepa/perllib/plugins/NPPlug.pm

    r3704 r13310  
    4646use BasPlug;
    4747use util;
     48use strict;
     49use unicode;
    4850
    4951sub BEGIN {
    50     @ISA = ('BasPlug');
    51 }
    52 
    53 use strict;
    54 
    55 sub print_usage {
    56     print STDERR "\nIncorrect options passed to NPPlug, check your collect.cfg configuration file\n";
    57 
    58     print STDERR "\n  usage: plugin NPPlug [options]\n\n";
    59     print STDERR "  options:\n";
    60     print STDERR "   -create_log            Creates a log file containing info about which portions\n";
    61     print STDERR "                          of papers are missing\n";
    62     print STDERR "   -logfile               Path of logfile (defaults to ./log.txt)\n\n";
    63 }
     52    @NPPlug::ISA = ('BasPlug');
     53}
     54
     55
     56my $arguments =
     57    [
     58     { 'name' => "create_log",
     59       'desc' => "To create a log file",
     60       'type' => "flag" },
     61     { 'name' => "logfile",
     62       'desc' => "The log file path",
     63       'type' => "string",
     64       'deft' => "./log.txt"}
     65     ];
     66
     67my $options = { 'name'     => "NPPlug",
     68        'desc'     => "{NPPlug.desc}",
     69        'abstract' => "no",
     70        'inherits' => "yes",
     71        'args'     => $arguments };
    6472
    6573sub new {
    66     my ($class) = @_;
    67     my $self = new BasPlug ();
    68 
    69     if (!parsargv::parse(\@_,
    70              q^create_log^, \$self->{'create_log'},
    71              q^logfile/.*/./log.txt^, \$self->{'logfile'})) {
    72     &print_usage();
    73     die "\n";
    74     }
     74    my ($class) = shift(@_);
     75
     76    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
     77    push(@$pluginlist, $class);
     78   
     79    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
     80    if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
     81   
     82    my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
    7583
    7684    $self->{'commentaries'} = {};
     
    8189    return bless $self, $class;
    8290}
     91
     92
     93sub get_default_process_exp {
     94    my $self = shift (@_);
     95   
     96    # the last option is an attempt to encode the concept of an html query ...
     97    return q^(?i)(\.issue)$^;
     98}
     99
    83100
    84101sub is_recursive {
     
    152169    return 0 if $filename =~ /meta\.txt$/i;
    153170
    154     return undef unless ($filename =~ /\.(issue|commentary)$/i && (-e $filename));
     171    return undef unless ($filename =~ /\.(issue|commentary|gif)$/i && (-e $filename));
    155172
    156173    $self->{'verbosity'} = $processor->{'verbosity'};
     
    163180    if ($filename =~ /\.commentary$/i) {
    164181    # commentary
    165     return $self->process_commentary ($filename, $issuekey, $dir, $file, $processor);
     182    $self->{'num_processed'}
     183      += $self->process_commentary ($filename, $issuekey, $dir, $file, $processor);
     184    return 1;
     185    }
     186
     187    if ($filename =~ /(.*)on\.gif$/i) {
     188    my $root = $1;
     189    # create surrogate document to store cover image (on and off) for
     190    # newspaper
     191
     192    $issuekey =~ s/on$//;
     193
     194    my $doc_obj = new doc  ($dir, "indexed_doc");
     195    my $cover = &util::filename_cat ($dir, $issuekey);
     196
     197    $self->associate_cover_images ($doc_obj, $cover, "" );
     198    $doc_obj->set_OID ($issuekey);
     199    $processor->process ($doc_obj);
     200
     201    return 0;
     202    }
     203    if ($filename =~ /(.*)of\.gif$/i) {
     204    # block it
     205    return 0;
     206    }
     207    if ($filename =~ /\.gif$/i) {
     208    # Let some other plugin have a go
     209    return undef;
    166210    }
    167211
    168212    my $numprocessed = 0;
    169     $self->{'commentaries'}->{$issuekey} = 0 unless defined $self->{'commentaries'}->{$issuekey};
     213    $self->{'commentaries'}->{$issuekey} = 0
     214    unless defined $self->{'commentaries'}->{$issuekey};
    170215
    171216    my ($abstractfile) = $file =~ /^([^\.]*)\.issue/i;
     
    188233    }
    189234
    190     return $numprocessed;
     235    $self->{'num_processed'} += $numprocessed;
     236
     237
     238
     239    return 1;
    191240}
    192241
     
    202251    $doc_obj->set_utf8_metadata_element ($topsection, 'abstract', $abstract) if defined $abstract;
    203252    $self->set_main_metadata ($doc_obj, $dir);
     253
     254    my $com_filename = &util::filename_cat($dir,"$issuekey.commentary");
     255    if (-e $com_filename) {
     256    $doc_obj->set_utf8_metadata_element ($topsection, "hascom", "1");
     257    }
    204258
    205259    # process issue's pdf if one exists
Note: See TracChangeset for help on using the changeset viewer.