Ignore:
Timestamp:
2013-11-19T11:51:13+13:00 (10 years ago)
Author:
kjdon
Message:

moved common import./export options to here. and moved checking collect.cfg for the specific options out to import/export.pl. groupsize is now just for GreenstoneXML plugout as that is the only format it was used for anyway. export now has a saveas_options option, which is used to pass options to the plugout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/inexport.pm

    r28211 r28641  
    4848use File::Basename;
    4949
     50my $oidtype_list =
     51    [ { 'name' => "hash",
     52        'desc' => "{import.OIDtype.hash}" },
     53      { 'name' => "hash_on_full_filename",
     54        'desc' => "{import.OIDtype.hash_on_full_filename}" },
     55      { 'name' => "assigned",
     56        'desc' => "{import.OIDtype.assigned}" },
     57      { 'name' => "incremental",
     58        'desc' => "{import.OIDtype.incremental}" },
     59      { 'name' => "filename",
     60        'desc' => "{import.OIDtype.filename}" },
     61      { 'name' => "dirname",
     62        'desc' => "{import.OIDtype.dirname}" },
     63      { 'name' => "full_filename",
     64        'desc' => "{import.OIDtype.full_filename}" } ];
     65
     66$inexport::directory_arguments =
     67[
     68      { 'name' => "importdir",
     69    'desc' => "{import.importdir}",
     70    'type' => "string",
     71    'reqd' => "no",
     72        'hiddengli' => "yes" },
     73      { 'name' => "collectdir",
     74    'desc' => "{import.collectdir}",
     75    'type' => "string",
     76    # parsearg left "" as default
     77    #'deft' => &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "collect"),
     78    'deft' => "",
     79    'reqd' => "no",
     80        'hiddengli' => "yes" },
     81 
     82];
     83$inexport::arguments =
     84[
     85      # don't set the default to hash - want to allow this to come from
     86      # entry in collect.cfg but want to override it here
     87      { 'name' => "OIDtype",
     88    'desc' => "{import.OIDtype}",
     89    'type' => "enum",
     90    'list' => $oidtype_list,
     91    # parsearg left "" as default
     92    #'deft' => "hash",
     93    'reqd' => "no",
     94    'modegli' => "2" },
     95      { 'name' => "OIDmetadata",
     96    'desc' => "{import.OIDmetadata}",
     97    'type' => "string",
     98     #'type' => "metadata", #doesn't work properly in GLI
     99    # parsearg left "" as default
     100    #'deft' => "dc.Identifier",
     101    'reqd' => "no",
     102    'modegli' => "2" },
     103      { 'name' => "site",
     104    'desc' => "{import.site}",
     105    'type' => "string",
     106    'deft' => "",
     107    'reqd' => "no",
     108        'hiddengli' => "yes" },
     109      { 'name' => "manifest",
     110    'desc' => "{import.manifest}",
     111    'type' => "string",
     112    'deft' => "",
     113    'reqd' => "no",
     114        'hiddengli' => "yes" } ,
     115     { 'name' => "incremental",
     116    'desc' => "{import.incremental}",
     117    'type' => "flag",
     118    'hiddengli' => "yes" },
     119      { 'name' => "keepold",
     120    'desc' => "{import.keepold}",
     121    'type' => "flag",
     122    'reqd' => "no",
     123    'hiddengli' => "yes" },
     124      { 'name' => "removeold",
     125    'desc' => "{import.removeold}",
     126    'type' => "flag",
     127    'reqd' => "no",
     128    'hiddengli' => "yes" },
     129      { 'name' => "language",
     130    'desc' => "{scripts.language}",
     131    'type' => "string",
     132    'reqd' => "no",
     133    'hiddengli' => "yes" },
     134      { 'name' => "maxdocs",
     135    'desc' => "{import.maxdocs}",
     136    'type' => "int",
     137    'reqd' => "no",
     138    # parsearg left "" as default
     139    #'deft' => "-1",
     140    'range' => "1,",
     141    'modegli' => "1" },
     142       { 'name' => "debug",
     143    'desc' => "{import.debug}",
     144    'type' => "flag",
     145    'reqd' => "no",
     146        'hiddengli' => "yes" },
     147      { 'name' => "faillog",
     148    'desc' => "{import.faillog}",
     149    'type' => "string",
     150    # parsearg left "" as default
     151    #'deft' => &FileUtils::filenameConcatenate("<collectdir>", "colname", "etc", "fail.log"),
     152    'deft' => "",
     153    'reqd' => "no",
     154        'modegli' => "3" },
     155       { 'name' => "out",
     156    'desc' => "{import.out}",
     157    'type' => "string",
     158    'deft' => "STDERR",
     159    'reqd' => "no",
     160        'hiddengli' => "yes" },
     161      { 'name' => "statsfile",
     162    'desc' => "{import.statsfile}",
     163    'type' => "string",
     164    'deft' => "STDERR",
     165    'reqd' => "no",
     166        'hiddengli' => "yes" },
     167      { 'name' => "verbosity",
     168    'desc' => "{import.verbosity}",
     169    'type' => "int",
     170    'range' => "0,",
     171    # parsearg left "" as default
     172    # 'deft' => "2",
     173    'reqd' => "no",
     174    'modegli' => "3" },
     175      { 'name' => "gli",
     176    'desc' => "{scripts.gli}",
     177    'type' => "flag",
     178    'reqd' => "no",
     179    'hiddengli' => "yes" },
     180      { 'name' => "xml",
     181    'desc' => "{scripts.xml}",
     182    'type' => "flag",
     183    'reqd' => "no",
     184    'hiddengli' => "yes" },
     185
     186];
     187
    50188sub new
    51189{
     
    101239    if ($intArgLeftinAfterParsing != 1 || (@$argv && $argv->[0] =~ /^\-+h/))
    102240    {
     241    ## TODO if we had invalid arg, can we signla that to user???
    103242    &PrintUsage::print_txt_usage($options, "{import.params}");
    104243    die "\n";
     
    306445    }
    307446
    308     if ((defined $self->{'groupsize'}) && ($self->{'groupsize'} == 1)) {
    309     if (defined $collectcfg->{'groupsize'} && $collectcfg->{'groupsize'} =~ /\d+/) {
    310         $self->{'groupsize'} = $collectcfg->{'groupsize'};
    311     }
    312     }
    313    
    314     if (!defined $self->{'saveas'}
    315     || ($self->{'saveas'} !~ /^(GreenstoneXML|GreenstoneMETS)$/ )) {
    316     # saveas was either not defined on the command-line, or it was not one of the recognized values
    317     if (defined $collectcfg->{'saveas'}
    318         && $collectcfg->{'saveas'} =~ /^(GreenstoneXML|GreenstoneMETS)$/) {
    319         $self->{'saveas'} = $collectcfg->{'saveas'};
    320     } else {
    321         $self->{'saveas'} = "GreenstoneXML"; # the default
    322     }
    323     }
     447   
    324448
    325449    if (!defined $self->{'OIDtype'}
     
    342466    }
    343467
    344     my $sortmeta = $self->{'sortmeta'};
    345     if (defined $collectcfg->{'sortmeta'} && (!defined $sortmeta || $sortmeta eq "")) {
    346     $sortmeta = $collectcfg->{'sortmeta'};
    347     }
    348     # sortmeta cannot be used with group size
    349     $sortmeta = undef unless defined $sortmeta && $sortmeta =~ /\S/;
    350     if (defined $sortmeta && $self->{'groupsize'} > 1) {
    351     &gsprintf($out, "{import.cannot_sort}\n\n");
    352     $sortmeta = undef;
    353     }
    354     if (defined $sortmeta) {
    355     &gsprintf($out, "{import.sortmeta_paired_with_ArchivesInfPlugin}\n\n");
    356     }
    357     $self->{'sortmeta'} = $sortmeta;
    358 
    359     if (defined $collectcfg->{'removeprefix'} && $self->{'removeprefix'} eq "") {
    360     $self->{'removeprefix'} = $collectcfg->{'removeprefix'};
    361     }
    362    
    363     if (defined $collectcfg->{'removesuffix'} && $self->{'removesuffix'} eq "") {
    364     $self->{'removesuffix'} = $collectcfg->{'removesuffix'};
    365     }
    366468    if (defined $collectcfg->{'debug'} && $collectcfg->{'debug'} =~ /^true$/i) {
    367469    $self->{'debug'} = 1;
     
    391493      print STDERR "Warning: -manifest flag should not be specified without also setting -keepold or -incremental\n";
    392494    }
    393 }
     495    }
    394496
    395497sub process_files
     
    415517
    416518    my $saveas      = $self->{'saveas'};
     519    my $saveas_options = $self->{'saveas_options'};
    417520    my $OIDtype     = $self->{'OIDtype'};
    418521    my $OIDmetadata = $self->{'OIDmetadata'};
     
    549652        }
    550653    }
     654
    551655    }
    552656    else {
     
    566670    my $plugout_name = $plugout->[0];
    567671
     672    if ($inexport_mode eq "export" && defined $saveas_options) {
     673    my @user_plugout_options = split(" ", $saveas_options);
     674    push @$plugout, @user_plugout_options;
     675    }
    568676    push @$plugout,("-output_info",$archive_info)  if (defined $archive_info);
    569677    push @$plugout,("-verbosity",$verbosity)       if (defined $verbosity);
    570678    push @$plugout,("-debug")                      if ($debug);
    571     push @$plugout,("-group_size",$groupsize)      if (defined $groupsize);
    572679    push @$plugout,("-gzip_output")                if ($gzip);
    573680    push @$plugout,("-output_handle",$out)         if (defined $out);
     
    575682    push @$plugout,("-xslt_file",$xsltfile)        if (defined $xsltfile && $xsltfile ne "");
    576683
     684    if ($inexport_mode eq "import") {
     685    if ($plugout_name =~ m/^GreenstoneXMLPlugout$/) {
     686        push @$plugout,("-group_size",$groupsize)      if (defined $groupsize);
     687    }
     688    }
    577689    if ($plugout_name =~ m/^MARCXMLPlugout$/) {
    578690    push @$plugout,("-group")                      if ($group_marc);
     
    8981010    }
    8991011
    900     # write out the archive information file
    901     $processor->close_file_output() if (defined $groupsize) && ($groupsize > 1);
     1012    # signal to the processor (plugout) that we have finished processing - if we are group processing, then the final output file needs closing.
    9021013    $processor->close_group_output() if $processor->is_group();
    9031014
    904     # for backwards compatability with archvies.inf file
    905     if ($arcinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
    906     $archive_info->save_info($arcinfo_doc_filename);
    907     }
    908     else {
    909     $archive_info->save_revinfo_db($arcinfo_src_filename);
    910     }
    911 
     1015#    if ($inexport_mode eq "import") {
     1016    # write out the archive information file
     1017    # for backwards compatability with archvies.inf file
     1018    if ($arcinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
     1019        $archive_info->save_info($arcinfo_doc_filename);
     1020    }
     1021    else {
     1022        $archive_info->save_revinfo_db($arcinfo_src_filename);
     1023    }
     1024#    }
    9121025    return $pluginfo;
    9131026}
     
    13801493}
    13811494
    1382 
     1495   
    138314961;
Note: See TracChangeset for help on using the changeset viewer.