Ignore:
Timestamp:
2010-07-18T16:36:56+12:00 (14 years ago)
Author:
davidb
Message:

Continued work on refactoring code to have better shared support for import.pl and export.pl

File:
1 edited

Legend:

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

    r22413 r22421  
    5151{
    5252    my $class = shift (@_);
    53     my ($argv,$options) = @_;
    54 
    55     my $self = { 'xml' => 0 };
     53    my ($mode,$argv,$options,$opt_listall_options) = @_;
     54
     55    my $self = { 'xml' => 0, 'mode' => $mode };
    5656
    5757    # general options available to all plugins
     
    7272    }
    7373
     74    if ($self->{'listall'}) {
     75    if ($self->{'xml'}) {
     76        &PrintUsage::print_xml_usage($opt_listall_options);
     77    }
     78    else
     79    {
     80        &PrintUsage::print_txt_usage($opt_listall_options,"{export.params}");
     81    }
     82    die "\n";
     83    }
     84
     85
    7486    if ($self->{'xml'}) {
    7587        &PrintUsage::print_xml_usage($options);
     
    151163
    152164    # Read in the collection configuration file.
    153     my ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
    154     my $collectcfg = &colcfg::read_collection_cfg ($configfilename, $gs_mode);
    155 
    156     return $collectcfg;
     165    my ($config_filename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
     166    my $collectcfg = &colcfg::read_collection_cfg ($config_filename, $gs_mode);
     167
     168    return ($config_filename,$collectcfg);
    157169}
    158170
     
    160172{
    161173    my $self = shift @_;
    162     my ($inexport_mode,$collectcfg) = @_;
     174    my ($collectcfg) = @_;
     175
     176    my $inexport_mode = $self->{'mode'};
    163177
    164178    my $verbosity  = $self->{'verbosity'};
    165     print STDERR "**** verbosity = $verbosity\n\n\n";
    166 
    167179    my $debug      = $self->{'debug'};
    168180    my $importdir  = $self->{'importdir'};
     
    218230    }
    219231    }
     232    $self->{'verbosity'} = $verbosity;
     233
    220234    if (defined $collectcfg->{'manifest'} && $self->{'manifest'} eq "") {
    221235    $self->{'manifest'} = $collectcfg->{'manifest'};
     
    235249    }
    236250    }
    237     if ($self->{'groupsize'} == 1) {
     251
     252    if ((defined $self->{'groupsize'}) && ($self->{'groupsize'} == 1)) {
    238253    if (defined $collectcfg->{'groupsize'} && $collectcfg->{'groupsize'} =~ /\d+/) {
    239254        $self->{'groupsize'} = $collectcfg->{'groupsize'};
     
    287302       
    288303    # check keepold and removeold
     304    my $checkdir = ($inexport_mode eq "import") ? "archives" : "export";
     305
    289306    my ($removeold, $keepold, $incremental, $incremental_mode)
    290307    = &scriptutil::check_removeold_and_keepold($self->{'removeold'}, $self->{'keepold'},
    291                            $self->{'incremental'}, "archives",
     308                           $self->{'incremental'}, $checkdir,
    292309                           $collectcfg);
    293310
     
    301318{
    302319    my $self = shift @_;
    303     my ($inexport_mode,$collectcfg) = @_;
     320    my ($config_filename,$collectcfg) = @_;
     321
     322    my $inexport_mode = $self->{'mode'};
    304323
    305324    my $verbosity   = $self->{'verbosity'};
     
    330349    my $removesuffix = $self->{'removesuffix'};
    331350
    332     my $gli         = $self->{'gli'};
    333 
    334     print STDERR "<Import>\n" if $gli;
     351    my $gli          = $self->{'gli'};
     352
     353    # related to export
     354    my $xsltfile         = $self->{'xsltfile'};
     355    my $group_marc       = $self->{'group_marc'};
     356    my $mapping_file     = $self->{'mapping_file'};
     357    my $xslt_mets        = $self->{'xslt_mets'};
     358    my $xslt_txt         = $self->{'xslt_txt'};
     359    my $fedora_namespace = $self->{'fedora_namespace'};
     360
     361    if ($inexport_mode eq "import") {
     362    print STDERR "<Import>\n" if $gli;
     363    }
     364    else {
     365    print STDERR "<export>\n" if $gli;
     366    }
    335367   
    336368    my $manifest_lookup = new manifest($collectcfg->{'infodbtype'},$archivedir);
     
    358390    #some global options for the plugins
    359391    my @global_opts = ();
    360 
    361392
    362393    my $pluginfo = &plugin::load_plugins ($plugins, $verbosity, $out, $faillog, \@global_opts, $incremental_mode);
     
    403434
    404435    ####Use Plugout####
    405     my ($plugout);
    406     if (defined $collectcfg->{'plugout'}) {
    407     # If a plugout was specified in the collect.cfg file, assume it is sensible
    408     # We can't check the name because it could be anything, if it is a custom plugout
    409     $plugout = $collectcfg->{'plugout'};
    410     }
    411     else{
    412     if ($saveas !~ /^(GreenstoneXML|GreenstoneMETS)$/) {
    413         push @$plugout,"GreenstoneXMLPlugout";
     436    my $plugout;
     437
     438    if ($inexport_mode eq "import") {
     439    if (defined $collectcfg->{'plugout'}) {
     440        # If a plugout was specified in the collect.cfg file, assume it is sensible
     441        # We can't check the name because it could be anything, if it is a custom plugout
     442        $plugout = $collectcfg->{'plugout'};
    414443    }
    415444    else{
    416         push @$plugout,$saveas."Plugout";
    417     }
    418     }
    419 
    420     push @$plugout,("-output_info",$archive_info) if (defined $archive_info);
    421     push @$plugout,("-verbosity",$verbosity)      if (defined $verbosity);
    422     push @$plugout,("-gzip_output")               if ($gzip);
    423     push @$plugout,("-group_size",$groupsize)     if (defined $groupsize);
    424     push @$plugout,("-output_handle",$out)        if (defined);
    425     push @$plugout,("-debug")                     if ($debug);
    426    
     445        if ($saveas !~ /^(GreenstoneXML|GreenstoneMETS)$/) {
     446        push @$plugout,"GreenstoneXMLPlugout";
     447        }
     448        else{
     449        push @$plugout,$saveas."Plugout";
     450        }
     451    }
     452    }
     453    else {
     454    if (defined $collectcfg->{'plugout'} && $collectcfg->{'plugout'} =~ /^(.*METS|DSpace|MARCXML)Plugout/) {
     455        $plugout = $collectcfg->{'plugout'};
     456    }
     457    else{
     458        if ($saveas !~ /^(GreenstoneMETS|FedoraMETS|DSpace|MARCXML)$/) {
     459        push @$plugout,"GreenstoneMETSPlugout";
     460        }
     461        else{
     462        push @$plugout,$saveas."Plugout";
     463        }
     464    }
     465    }
     466   
     467    my $plugout_name = $plugout->[0];
     468
     469    push @$plugout,("-output_info",$archive_info)  if (defined $archive_info);
     470    push @$plugout,("-verbosity",$verbosity)       if (defined $verbosity);
     471    push @$plugout,("-debug")                      if ($debug);
     472    push @$plugout,("-group_size",$groupsize)      if (defined $groupsize);
     473    push @$plugout,("-gzip_output")                if ($gzip);
     474    push @$plugout,("-output_handle",$out)         if (defined $out);
     475
     476    push @$plugout,("-xslt_file",$xsltfile)        if (defined $xsltfile && $xsltfile ne "");
     477
     478    if ($plugout_name =~ m/^MARCXMLPlugout$/) {
     479    push @$plugout,("-group")                      if ($group_marc);
     480    push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $mapping_file ne "");
     481    }
     482    if ($plugout_name =~ m/^.*METSPlugout$/) {
     483    push @$plugout,("-xslt_mets",$xslt_mets)       if (defined $xslt_mets && $xslt_mets ne "");
     484    push @$plugout,("-xslt_txt",$xslt_txt)         if (defined $xslt_txt && $xslt_txt ne "");
     485    }
     486
     487    if ($plugout_name eq "FedoraMETSPlugout") {
     488    push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $fedora_namespace ne "");
     489    }
     490
     491
    427492    my $processor = &plugout::load_plugout($plugout);                       
    428493    $processor->setoutputdir ($archivedir);
     
    443508    &plugin::file_block_read($pluginfo, $importdir, "", $block_hash, $metadata, $gli);
    444509
    445 
    446510    if ($incremental || $incremental_mode eq "onlyadd") {
    447511
    448512        prime_doc_oid_count($archivedir);
    449 
    450513
    451514        # Can now work out which files were new, already existed, and have
     
    532595    &plugin::remove_some($pluginfo, $collectcfg->{'infodbtype'}, $archivedir, \@full_deleted_files);
    533596    mark_docs_for_deletion($archive_info,{},
    534                       \@full_deleted_files,
    535                       $archivedir, $verbosity, "delete");
     597                   \@full_deleted_files,
     598                   $archivedir, $verbosity, "delete");
    536599
    537600
     
    574637    }
    575638
     639    if ($saveas eq "FedoraMETS") {
     640    # create collection "doc obj" for Fedora that contains
     641    # collection-level metadata
     642   
     643    my $doc_obj = new doc($config_filename,"nonindexed_doc","none");
     644    $doc_obj->set_OID("collection");
     645   
     646    my $col_name = undef;
     647    my $col_meta = $collectcfg->{'collectionmeta'};
     648   
     649    if (defined $col_meta) {       
     650        store_collectionmeta($col_meta,"collectionname",$doc_obj); # in GS3 this is a collection's name
     651        store_collectionmeta($col_meta,"collectionextra",$doc_obj); # in GS3 this is a collection's description     
     652    }
     653    $processor->process($doc_obj);
     654    }
     655
    576656    &plugin::end($pluginfo, $processor);
    577657
     
    586666    $processor->close_group_output() if $processor->is_group();
    587667
    588 # The following 'if' statement is in the export.pl version of the script,
    589 # The reason for the 'if' statement is now given in export.pl
    590 # Unclear at this point if the same should be done here
    591 ##    if (($saveas =~ m/^.*METS$/) || ($saveas eq "MARC")) {
    592     # Not all export types need this (e.g. DSpace)
    593 
    594     # should we still do this in debug mode??
    595 
    596668    # for backwards compatability with archvies.inf file
    597669    if ($arcinfo_doc_filename =~ m/(contents)|(\.inf)$/) {
     
    602674    }
    603675
    604 
    605 ##    }
    606 
    607676    return $pluginfo;
    608677}
     
    612681{
    613682    my $self = shift @_;
    614     my ($inexport_mode,$pluginfo) = @_;
     683    my ($pluginfo) = @_;
     684
     685    my $inexport_mode = $self->{'mode'};
    615686
    616687    my $statsfile = $self->{'statsfile'};
     
    634705    &gsprintf($out, "\n");
    635706    &gsprintf($out, "*********************************************\n");
    636     &gsprintf($out, "{import.complete}\n");
     707    &gsprintf($out, "{$inexport_mode.complete}\n");
    637708    &gsprintf($out, "*********************************************\n");
    638709
Note: See TracChangeset for help on using the changeset viewer.