Changeset 28705 for main


Ignore:
Timestamp:
2013-11-28T15:00:56+13:00 (10 years ago)
Author:
kjdon
Message:

args can set their defaults in the data structure - we now use default_argname variable to test whether value was set by the user or parse function. Can specify folder name instead of full path for import/archives dir options - will be generated inside collection's folder. -generate_auxiliary_files used to determine whether to output the archivesinf databases or not.

File:
1 edited

Legend:

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

    r28641 r28705  
    7070    'type' => "string",
    7171    'reqd' => "no",
     72    'deft' => "import",
    7273        'hiddengli' => "yes" },
    7374      { 'name' => "collectdir",
     
    8990    'type' => "enum",
    9091    'list' => $oidtype_list,
    91     # parsearg left "" as default
    92     #'deft' => "hash",
     92    'deft' => "hash_on_full_filename",
    9393    'reqd' => "no",
    9494    'modegli' => "2" },
     
    9696    'desc' => "{import.OIDmetadata}",
    9797    'type' => "string",
    98      #'type' => "metadata", #doesn't work properly in GLI
    99     # parsearg left "" as default
    100     #'deft' => "dc.Identifier",
     98    'deft' => "dc.Identifier",
    10199    'reqd' => "no",
    102100    'modegli' => "2" },
     
    136134    'type' => "int",
    137135    'reqd' => "no",
    138     # parsearg left "" as default
    139     #'deft' => "-1",
    140     'range' => "1,",
     136    'deft' => "-1",
     137    'range' => "-1,",
    141138    'modegli' => "1" },
    142139       { 'name' => "debug",
     
    169166    'type' => "int",
    170167    'range' => "0,",
    171     # parsearg left "" as default
    172     # 'deft' => "2",
     168    'deft' => "2",
    173169    'reqd' => "no",
    174170    'modegli' => "3" },
     
    239235    if ($intArgLeftinAfterParsing != 1 || (@$argv && $argv->[0] =~ /^\-+h/))
    240236    {
    241     ## TODO if we had invalid arg, can we signla that to user???
     237    ## TODO if we had invalid arg, can we signal that to user???
    242238    &PrintUsage::print_txt_usage($options, "{import.params}");
    243239    die "\n";
     
    356352    my $inexport_mode = $self->{'mode'};
    357353
    358     my $verbosity  = $self->{'verbosity'};
    359     my $debug      = $self->{'debug'};
    360354    my $importdir  = $self->{'importdir'};
    361     my $archivedir = $self->{'archivedir'} || $self->{'exportdir'} || "";
     355    my $archivedir = $self->{'archivedir'} || $self->{'exportdir'};
    362356    my $out        = $self->{'out'};
    363357
     
    372366    }
    373367
    374     if (defined $collectcfg->{'importdir'} && $importdir eq "") {
     368    if (defined $self->{'default_importdir'} && defined $collectcfg->{'importdir'}) {
    375369    $importdir = $collectcfg->{'importdir'};
    376370    }
    377     if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
    378     $archivedir = $collectcfg->{'archivedir'};
     371
     372    if ($inexport_mode eq "import") {
     373    if ( defined $self->{'default_archivedir'} && defined $collectcfg->{'archivedir'}) {
     374        $archivedir = $collectcfg->{'archivedir'};
     375    }
     376    }
     377    elsif ($inexport_mode eq "export") {
     378    if (defined $self->{'default_exportdir'} && defined $collectcfg->{'exportdir'}) {
     379        $archivedir = $collectcfg->{'exportdir'};
     380    }
    379381    }
    380382    # fill in the default import and archives directories if none
    381383    # were supplied, turn all \ into / and remove trailing /
    382     if ($importdir eq "")
     384    if (!&FileUtils::isFilenameAbsolute($importdir))
    383385    {
    384       $importdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "import");
     386      $importdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, $importdir);
    385387    }
    386388    else
     
    399401    $self->{'importdir'} = $importdir;
    400402
    401     if ($archivedir eq "") {
    402     if ($inexport_mode eq "import") {
    403         $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "archives");
    404     }
    405     elsif ($inexport_mode eq "export") {
    406         $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "export");
    407     }
    408     else {
    409         print STDERR "Warning: Unrecognized import/export mode '$inexport_mode'\n";
    410         print STDERR "         Defaulting to 'archives' for file output\n";
    411         $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, "archives");
    412     }
    413     }
    414 
    415     $archivedir = &FileUtils::sanitizePath($archivedir);
    416     #$archivedir =~ s/[\\\/]+/\//g;
    417     #$archivedir =~ s/\/$//;
     403    if (!&FileUtils::isFilenameAbsolute($archivedir)) {
     404    $archivedir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, $archivedir);
     405    }
     406    else {
     407   
     408    $archivedir = &FileUtils::sanitizePath($archivedir);
     409    }
    418410    $self->{'archivedir'} = $archivedir;
    419411
    420     if ($verbosity !~ /\d+/) {
     412    if (defined $self->{'default_verbosity'}) {
    421413    if (defined $collectcfg->{'verbosity'} && $collectcfg->{'verbosity'} =~ /\d+/) {
    422         $verbosity = $collectcfg->{'verbosity'};
    423     } else {
    424         $verbosity = 2; # the default
    425     }
    426     }
    427     $self->{'verbosity'} = $verbosity;
    428 
     414        $self->{'verbosity'} = $collectcfg->{'verbosity'};
     415    }
     416    }
     417 
    429418    if (defined $collectcfg->{'manifest'} && $self->{'manifest'} eq "") {
    430419    $self->{'manifest'} = $collectcfg->{'manifest'};
     
    437426    }
    438427
    439     if ($self->{'maxdocs'} !~ /\-?\d+/) {
     428    if (defined $self->{'default_maxdocs'}) {
    440429    if (defined $collectcfg->{'maxdocs'} && $collectcfg->{'maxdocs'} =~ /\-?\d+/) {
    441430        $self->{'maxdocs'} = $collectcfg->{'maxdocs'};
    442     } else {
    443         $self->{'maxdocs'} = -1; # the default
    444431    }
    445432    }
     
    447434   
    448435
    449     if (!defined $self->{'OIDtype'}
    450     || ($self->{'OIDtype'} !~ /^(hash|hash_on_full_filename|incremental|assigned|filename|dirname|full_filename)$/ )) {
    451     # OIDtype was either not defined on the command-line, or if it was not one of the recognized values
     436    if (defined $self->{'default_OIDtype'} ) {
    452437    if (defined $collectcfg->{'OIDtype'}
    453438        && $collectcfg->{'OIDtype'} =~ /^(hash|hash_on_full_filename|incremental|assigned|filename|dirname|full_filename)$/) {
    454439        $self->{'OIDtype'} = $collectcfg->{'OIDtype'};
    455     } else {
    456         $self->{'OIDtype'} = "hash"; # the default
    457     }
    458     }
    459 
    460     if ((!defined $self->{'OIDmetadata'}) || ($self->{'OIDmetadata'} eq "")) {
     440    }
     441    }
     442
     443    if (defined $self->{'default_OIDmetadata'}) {
    461444    if (defined $collectcfg->{'OIDmetadata'}) {
    462445        $self->{'OIDmetadata'} = $collectcfg->{'OIDmetadata'};
    463     } else {
    464         $self->{'OIDmetadata'} = "dc.Identifier"; # the default
    465     }
     446    }
    466447    }
    467448
     
    638619    my $plugout;
    639620
     621    my $generate_auxiliary_files = 0;
     622    if ($inexport_mode eq "import") {
     623    $generate_auxiliary_files = 1;
     624    }
     625    elsif ($self->{'include_auxiliary_database_files'}) {
     626    $generate_auxiliary_files = 1;
     627    }
     628    $self->{'generate_auxiliary_files'} = $generate_auxiliary_files;
     629
     630    # Option to use user defined plugout
    640631    if ($inexport_mode eq "import") {
    641632    if (defined $collectcfg->{'plugout'}) {
    642633        # If a plugout was specified in the collect.cfg file, assume it is sensible
    643634        # We can't check the name because it could be anything, if it is a custom plugout
     635        print STDERR "Using plugout specified in collect.cfg: $collectcfg->{'plugout'}\n";
    644636        $plugout = $collectcfg->{'plugout'};
    645637    }
    646     else{
    647         if ($saveas !~ /^(GreenstoneXML|GreenstoneMETS)$/) {
    648         push @$plugout,"GreenstoneXMLPlugout";
    649         }
    650         else{
    651         push @$plugout,$saveas."Plugout";
    652         }
     638    else {
     639        push @$plugout,$saveas."Plugout";
    653640    }
    654641
    655642    }
    656643    else {
    657     if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
     644    if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(GreenstoneXML|.*METS|DSpace|MARCXML)Plugout/) {
    658645        $plugout = $collectcfg->{'plugout'};
    659     }
    660     else{
    661         if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
    662         push @$plugout,"GreenstoneMETSPlugout";
    663         }
    664         else{
    665         push @$plugout,$saveas."Plugout";
    666         }
    667     }
    668     }
    669    
     646        print STDERR "Using plugout specified in collect.cfg: $collectcfg->{'plugout'}\n";
     647    }
     648    else {
     649        push @$plugout,$saveas."Plugout";
     650    }
     651    }
     652
    670653    my $plugout_name = $plugout->[0];
    671654
     
    681664
    682665    push @$plugout,("-xslt_file",$xsltfile)        if (defined $xsltfile && $xsltfile ne "");
    683 
     666    push @$plugout, ("-no_auxiliary_databases") if ($generate_auxiliary_files == 0);
    684667    if ($inexport_mode eq "import") {
    685668    if ($plugout_name =~ m/^GreenstoneXMLPlugout$/) {
     
    687670    }
    688671    }
    689     if ($plugout_name =~ m/^MARCXMLPlugout$/) {
    690     push @$plugout,("-group")                      if ($group_marc);
    691     push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "");
    692     }
    693     if ($plugout_name =~ m/^.*METSPlugout$/) {
    694     push @$plugout,("-xslt_mets",$xslt_mets)       if (defined $xslt_mets && $xslt_mets ne "");
    695     push @$plugout,("-xslt_txt",$xslt_txt)         if (defined $xslt_txt && $xslt_txt ne "");
    696     }
    697 
    698     if ($plugout_name eq "FedoraMETSPlugout") {
    699     push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "");
    700     }
    701    
    702     if ($plugout_name eq "DSpacePlugout") {
    703     push @$plugout,("-metadata_prefix",$metadata_prefix) if (defined $metadata_prefix && $metadata_prefix ne "");   
    704     }
    705 
    706672    my $processor = &plugout::load_plugout($plugout);
    707673    $processor->setoutputdir ($archivedir);
    708674    $processor->set_sortmeta ($sortmeta, $removeprefix, $removesuffix) if defined $sortmeta;
    709 
    710675    $processor->set_OIDtype ($OIDtype, $OIDmetadata);
    711    
     676    $processor->begin();
    712677    &plugin::begin($pluginfo, $importdir, $processor, $maxdocs, $gli);
    713678   
     
    964929    # oailastmodified and oailastmodifieddate
    965930    my $earliestDatestampFile = &FileUtils::filenameConcatenate($archivedir, "earliestDatestamp");
     931    if ($self->{'generate_auxiliary_files'}) {
    966932    if (!-f $earliestDatestampFile && -d $archivedir) {
    967933    my $current_time_in_seconds = time; # in seconds
     
    977943
    978944    }
    979 
     945    }
    980946   
    981947    $self->perform_process_files($manifest, $pluginfo, $importdir, '', $block_hash, $metadata, $processor, $maxdocs);
     
    1014980
    1015981#    if ($inexport_mode eq "import") {
     982    if ($self->{'generate_auxiliary_files'}) {
    1016983    # write out the archive information file
    1017984    # for backwards compatability with archvies.inf file
     
    1022989        $archive_info->save_revinfo_db($arcinfo_src_filename);
    1023990    }
    1024 #    }
     991    }
    1025992    return $pluginfo;
    1026993}
Note: See TracChangeset for help on using the changeset viewer.