Ignore:
Timestamp:
2004-05-21T11:18:44+12:00 (20 years ago)
Author:
kjdon
Message:

plugin read functions now return 'undef' - didn't recognise, '-1' - recognised but had an error during processing, '0' - blocked or didn't process but don't pass it on to other plugins, or 'num_docs' processed. this emables a bit better error reporting about what has happened to each file. this now sends some more informative messages to GLI and general output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugin.pm

    r7351 r7363  
    3232         'num_blocked' => 0,
    3333         'num_not_processed' => 0,
     34         'num_not_recognised' => 0,
    3435         'num_archives' => 0
    3536         };
     
    108109
    109110    my $rv = 0;
    110 
     111    my $glifile = $file;
     112    $glifile =~ s/^[\/\\]+//; # file sometimes starts with a / so get rid of it
    111113    # Announce to GLI that we are handling a file
    112     print STDERR "<File n='$file'>\n" if $gli;
     114    print STDERR "<File n='$glifile'>\n" if $gli;
    113115
    114116    # the .kill file is a handy (if not very elegant) way of aborting
     
    116118    if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
    117119    &gsprintf($outhandle, "{plugin.kill_file}\n");
    118     # print $outhandle "Process killed by .kill file\n";
    119120    die "\n";
    120121    }
    121122   
     123    my $had_error = 0;
    122124    # pass this file by each of the plugins in turn until one
    123125    # is found which will process it
     126    # read must return:
     127    # undef - could not recognise
     128    # -1 - tried but error
     129    # 0 - blocked
     130    # anything else for successful processing
    124131    foreach $plugobj (@$pluginfo) {
    125132    $rv = $plugobj->read($pluginfo, $base_dir, $file,
    126133                 $metadata, $processor, $maxdocs, $gli, $aux);
    127     return $rv if defined $rv;
    128     }
    129 
    130     if ($verbosity >= 2) {
    131     &gsprintf($outhandle, "{plugin.no_plugin_could_process}\n", $file);
    132     # print $outhandle "WARNING - no plugin could process $file\n";
    133     }
    134     # tell the GLI that it was not processed
    135     print STDERR "<Processing n='$file' p=''>\n" if $gli;
    136 
    137     $file =~ s/.*?([^\\\/]+)$/$1/;
    138     &gsprintf($failhandle, "$file: {plugin.no_plugin_could_process_this_file}\n");
    139     # print $failhandle "$file: no plugin could process this file\n";
    140     $stats->{'num_not_processed'} ++;
     134    if (defined $rv) {
     135        if ($rv == -1) {
     136        # an error has occurred
     137        $had_error = 1;
     138        print STDERR "<ProcessingError n='$glifile'>\n" if $gli;
     139        } else {
     140        return $rv;
     141        }
     142    } # else undefined - was not recognised by the plugin
     143    }
     144   
     145    if ($had_error) {
     146    # was recognised but couldn't be processed
     147    if ($verbosity >= 2) {
     148        &gsprintf($outhandle, "{plugin.no_plugin_could_process}\n", $file);
     149        # print $outhandle "WARNING - no plugin could process $file\n";
     150    }
     151    # tell the GLI that it was not processed
     152    print STDERR "<NonProcessedFile n='$glifile'>\n" if $gli;
     153   
     154    $file =~ s/.*?([^\\\/]+)$/$1/;
     155    &gsprintf($failhandle, "$file: {plugin.no_plugin_could_process_this_file}\n");
     156    # print $failhandle "$file: no plugin could process this file\n";
     157    $stats->{'num_not_processed'} ++;
     158    } else {
     159    # was not recognised
     160    if ($verbosity >= 2) {
     161        &gsprintf($outhandle, "{plugin.no_plugin_could_recognise}\n", $file);
     162        # print $outhandle "WARNING - no plugin could process $file\n";
     163    }
     164    # tell the GLI that it was not processed
     165    print STDERR "<NonRecognisedFile n='$glifile'>\n" if $gli;
     166   
     167    $file =~ s/.*?([^\\\/]+)$/$1/;
     168    &gsprintf($failhandle, "$file: {plugin.no_plugin_could_recognise_this_file}\n");
     169    # print $failhandle "$file: no plugin could process this file\n";
     170    $stats->{'num_not_recognised'} ++;
     171   
     172    }
    141173
    142174    return 0;
     
    156188
    157189    my $total = $stats->{'num_processed'} + $stats->{'num_blocked'} +
    158     $stats->{'num_not_processed'};
    159 
    160     print STDERR "<ImportComplete considered='$total' processed='$stats->{'num_processed'}' blocked='$stats->{'num_blocked'}' ignored='$stats->{'num_not_processed'}'>\n" if $gli;
     190    $stats->{'num_not_processed'} + $stats->{'num_not_recognised'};
     191
     192    print STDERR "<ImportComplete considered='$total' processed='$stats->{'num_processed'}' blocked='$stats->{'num_blocked'}' ignored='$stats->{'num_not_recognised'}' failed='$stats->{'num_not_processed'}'>\n" if $gli;
    161193
    162194    if ($total == 1) {
    163195    &gsprintf($statshandle, "* {plugin.one_considered}\n");
    164     # print $statshandle "* 1 document was considered for processing\n";
    165196    } else {
    166197    &gsprintf($statshandle, "* {plugin.n_considered}\n", $total);
    167     # print $statshandle "* $total documents were considered for processing\n";
    168198    }
    169199    if ($stats->{'num_archives'}) {
    170     # print $statshandle "   (including the contents of " . $stats->{'num_archives'} .
    171     #     " ZIP/TAR archive";
    172200    if ($stats->{'num_archives'} == 1) {
    173201        &gsprintf($statshandle, "   ({plugin.including_archive})\n");
    174         # print $statshandle ")\n";}
    175202    }
    176203    else {
    177204        &gsprintf($statshandle, "   ({plugin.including_archives})\n", $stats->{'num_archives'});
    178         # print $statshandle "s)\n";}
    179205    }
    180206    }
    181207    if ($stats->{'num_processed'} == 1) {
    182208    &gsprintf($statshandle, "* {plugin.one_included}\n");
    183     # print $statshandle "* 1 was processed and included in the collection\n";
    184209    } else {
    185210    &gsprintf($statshandle, "* {plugin.n_included}\n", $stats->{'num_processed'});
    186     # print $statshandle "* " . $stats->{'num_processed'} . " were processed and included in the collection\n";
     211    }
     212    if ($stats->{'num_not_recognised'}) {
     213    if ($stats->{'num_not_recognised'} == 1) {
     214        &gsprintf($statshandle, "* {plugin.one_unrecognised}\n");
     215    } else {
     216        &gsprintf($statshandle, "* {plugin.n_unrecognised}\n", $stats->{'num_not_recognised'});
     217    }
     218
    187219    }
    188220    if ($stats->{'num_not_processed'}) {
    189221    if ($stats->{'num_not_processed'} == 1) {
    190222        &gsprintf($statshandle, "* {plugin.one_rejected}\n");
    191         # print $statshandle "* 1 was rejected.";
    192223    } else {
    193224        &gsprintf($statshandle, "* {plugin.n_rejected}\n", $stats->{'num_not_processed'});
    194         # print $statshandle "* " . $stats->{'num_not_processed'} . " were rejected.";
    195     }
     225    }
     226    }
     227    if ($stats->{'num_not_processed'} || $stats->{'num_not_recognised'}) {
    196228    &gsprintf($statshandle, " {plugin.see_faillog}\n", $faillog);
    197     # print $statshandle " See $faillog for a list of rejected documents\n";
    198229    }
    199230}
Note: See TracChangeset for help on using the changeset viewer.