Ignore:
Timestamp:
2008-02-12T15:01:48+13:00 (16 years ago)
Author:
davidb
Message:

import.pl statements re-ordered to be more inkeeping with export.pl. The two programs share many similarities and at some point the common code should be moved out to a perl module and the scripts simplified to take advantage of that similarity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/bin/script/import.pl

    r14925 r14957  
    3939    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
    4040    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
     41
     42    if (defined $ENV{'GSDLEXTS'}) {
     43    my @extensions = split(/:/,$ENV{'GSDLEXTS'});
     44    foreach my $e (@extensions) {
     45        my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
     46
     47        unshift (@INC, "$ext_prefix/perllib");
     48        unshift (@INC, "$ext_prefix/perllib/cpan");
     49    }
     50    }
    4151}
     52
     53use strict;
     54no strict 'refs'; # allow filehandles to be variables and vice versa
     55no strict 'subs'; # allow barewords (eg STDERR) as function arguments
    4256
    4357use arcinfo;
     
    5569
    5670
    57 use strict;
    58 no strict 'refs'; # allow filehandles to be variables and vice versa
    59 no strict 'subs'; # allow barewords (eg STDERR) as function arguments
    60 
    6171my $oidtype_list =
    6272    [ { 'name' => "hash",
     
    6979        'desc' => "{import.OIDtype.dirname}" } ];
    7080
    71 #** define to use the original GA format or METS format
     81
     82# used to control output file format
    7283my $saveas_list =
    73     [ { 'name' => "GA",
    74         'desc' => "{import.saveas.GA}" },
    75       { 'name' => "METS",
    76         'desc' => "{import.saveas.METS}" } ];
     84    [ { 'name' => "DSpace",
     85        'desc' => "{export.saveas.DSpace}" },
     86      { 'name' => "GreenstoneMETS",
     87        'desc' => "{export.saveas.GreenstoneMETS}"},
     88      { 'name' => "FedoraMETS",
     89        'desc' => "{export.saveas.FedoraMETS}"},
     90      { 'name' => "GA",
     91        'desc' => "{export.saveas.GA}"},
     92      { 'name' => "MARCXML",
     93        'desc' => "{export.saveas.MARCXML}"}
     94     ];
    7795
    7896
     
    85103# modegli: The lowest detail mode this argument is visible at in GLI
    86104
     105my $saveas_argument
     106    = { 'name' => "saveas",
     107    'desc' => "{import.saveas}",
     108    'type' => "enum",
     109    'list' => $saveas_list,
     110    'deft' => "GA",
     111    'reqd' => "no",
     112    'modegli' => "3" };
     113
     114
    87115my $arguments =
    88     [ { 'name' => "archivedir",
     116    [
     117      $saveas_argument,
     118      { 'name' => "archivedir",
    89119    'desc' => "{import.archivedir}",
     120    'type' => "string",
     121    'reqd' => "no",
     122        'hiddengli' => "yes" },
     123      { 'name' => "importdir",
     124    'desc' => "{import.importdir}",
    90125    'type' => "string",
    91126    'reqd' => "no",
     
    124159    'reqd' => "no",
    125160        'modegli' => "4" },
    126       { 'name' => "importdir",
    127     'desc' => "{import.importdir}",
    128     'type' => "string",
    129     'reqd' => "no",
    130         'hiddengli' => "yes" },
    131161      { 'name' => "incremental",
    132162    'desc' => "{import.incremental}",
     
    176206    'reqd' => "no",
    177207        'hiddengli' => "yes" },
    178       { 'name' => "saveas",
    179     'desc' => "{import.saveas}",
    180     'type' => "enum",
    181     'list' => $saveas_list,
    182     'deft' => "GA",
    183     'reqd' => "no",
    184     'modegli' => "3" },     
    185208      { 'name' => "sortmeta",
    186209    'desc' => "{import.sortmeta}",
     
    245268
    246269sub main {
    247     my ($verbosity, $importdir, $archivedir, $site, $manifest, $incremental, $keepold,
    248     $removeold, $saveas, $version,
    249     $gzip, $groupsize, $OIDtype, $OIDmetadata, $debug,
    250     $maxdocs, $collection, $configfilename, $collectcfg, $gs_mode,
    251     $pluginfo, $sortmeta, $removeprefix, $removesuffix,
    252     $archive_info_filename, $statsfile,
    253     $archive_info, $processor, $out, $faillog, $collectdir, $gli, $language);
     270    # params
     271    my ($language, $verbosity, $debug,
     272    $importdir, $site, $manifest, $incremental, $keepold,
     273    $removeold, $saveas,
     274    $OIDtype, $OIDmetadata,
     275    $maxdocs, $statsfile,
     276    $out, $faillog, $collectdir, $gli,
     277
     278    $archivedir,
     279    $gzip, $groupsize,
     280    $sortmeta, $removeprefix, $removesuffix,
     281    );
    254282
    255283    my $xml = 0;
     284
     285    # other vars
     286    my ($configfilename, $collectcfg, $collection,
     287    $archive_info_filename, $archive_info,
     288    $gs_mode,
     289    $processor, $pluginfo);
    256290
    257291    my $service = "import";
     
    261295    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    262296    # Parse returns -1 if something has gone wrong
    263     if($intArgLeftinAfterParsing == -1)
     297    if ($intArgLeftinAfterParsing == -1)
    264298    {
    265299    &PrintUsage::print_txt_usage($options, "{import.params}");
     
    408442    }
    409443    else{
    410     if ($saveas !~ /^(GA|METS)$/) {
     444    if ($saveas !~ /^(GA|.*METS|DSpace|MARCXML)$/) {
    411445        push @$plugout,"GAPlugout";
    412446    }
     
    493527
    494528    # read the archive information file
    495     $archive_info_filename = &util::filename_cat ($archivedir, "archives.inf");
     529
     530    # If saveas=DSpace, a "contents" file will be created, otherwise "archives.inf"
     531   
     532    # the plugouts should be doing this!!
     533    if ($saveas eq "DSpace"){
     534    $archive_info_filename = &util::filename_cat ($archivedir, "contents");
     535    } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "GA" || $saveas eq "MARC" ) {
     536    $archive_info_filename = &util::filename_cat ($archivedir, "archives.inf");
     537    }
     538
    496539    $archive_info = new arcinfo ();
    497540    $archive_info->load_info ($archive_info_filename);
     
    531574    }
    532575
     576    if ($saveas eq "FedoraMETS")
     577    {
     578    # This would be better (should?!) be done in Plugout!!
     579
     580    # create collection "doc obj" for Fedora that contains
     581    # collection-level metadata
     582   
     583    my $doc_obj = new doc($configfilename,"nonindexed_doc");
     584    $doc_obj->set_OID("collection");
     585   
     586    my $col_name = undef;
     587    my $col_meta = $collectcfg->{'collectionmeta'};
     588    if (defined $col_meta)
     589    {
     590        store_collectionmeta($col_meta,"collectionname",$doc_obj);
     591        store_collectionmeta($col_meta,"collectioextra",$doc_obj);
     592       
     593    }
     594   
     595    $processor->process($doc_obj);
     596    }
     597
     598
    533599    &plugin::end($pluginfo, $processor);
    534600
     
    538604    $processor->close_file_output() if $groupsize > 1;
    539605    $processor->close_group_output() if $processor->is_group();
    540     # should we still do this in debug mode??
    541     $archive_info->save_info($archive_info_filename);
     606
     607# The following 'if' statement is in the export.pl version of the script,
     608# but not (so far) the import.pl version.  Why is this?
     609##    if ($saveas =~ m/^.*METS$/) {
     610    # should we still do this in debug mode??
     611
     612    $archive_info->save_info($archive_info_filename);
     613##    }
    542614   
    543615    # write out import stats
Note: See TracChangeset for help on using the changeset viewer.