Changeset 38797 for main/trunk


Ignore:
Timestamp:
2024-02-27T14:43:48+13:00 (4 months ago)
Author:
kjdon
Message:

added option '-ignore_field' - if there is a column with this name in the spreadsheet, and a line is non empty for this column, then ignore the line.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/CSVPlugin.pm

    r37861 r38797  
    7474    'type' => "flag",
    7575    'reqd' => "no"},
     76       { 'name' => "ignore_field",
     77    'desc' => "{CSVPlugin.ignore_field}",
     78    'type' => "string",
     79    'reqd' => "no"},
    7680
    7781
     
    109113    if ((defined $self->{'use_namespace_for_field_names'}) && ($self->{'use_namespace_for_field_names'} =~ m/^\s*$/)) {
    110114    $self->{'use_namespace_for_field_names'} = undef;
     115    }
     116    if ((defined $self->{'ignore_field'}) && ($self->{'ignore_field'} =~ m/^\s*$/)) {
     117    $self->{'ignore_field'} = undef;
    111118    }
    112119
     
    226233    my $found_filename_field = 0;
    227234    my $filename_field = $self->{'filename_field'};
     235    my $ignore_field = $self->{'ignore_field'};
     236    my $ignore_col;
    228237    for (my $i = 0; $i < scalar(@csv_file_fields); $i++) {
    229238    # Remove any spaces from the field names, and surrounding quotes too
     
    232241    $csv_file_fields[$i] =~ s/"$//;
    233242
     243
    234244    if ($self->{'use_namespace_for_field_names'}) {
    235245        $csv_file_fields[$i] =  $self->{'use_namespace_for_field_names'}. "." . $csv_file_fields[$i];
     
    237247    if ($csv_file_fields[$i] eq  $filename_field) {
    238248        $found_filename_field = 1;
    239     }
     249    }
     250    if ($ignore_field && $csv_file_fields[$i] eq $ignore_field) {
     251        $ignore_col = $i;
     252    }
     253
    240254    }
    241255
     
    246260    }
    247261
     262
     263
    248264    my $count = 0;
    249265    while (my $csv_line = $csv->getline($CSV_FILE)) {
    250266    my @md_vals = @$csv_line;
     267   
     268    if (defined $ignore_col && $md_vals[$ignore_col] ne "") {
     269        # ignore this line
     270        print STDERR "ignoring line ".join(",", @md_vals)."\n";
     271        next;
     272    }
    251273    $count++;
    252 
     274   
    253275    # Build a hash of metadata name to metadata value for this line
    254276    my %csv_line_metadata;
Note: See TracChangeset for help on using the changeset viewer.