Changeset 14935


Ignore:
Timestamp:
2007-12-20T21:55:31+13:00 (14 years ago)
Author:
davidb
Message:

export.pl script updated to be more consistent with its import.pl counterpart, i.e. support for -incremental and -manifest; also modificed to use plugouts FedoraMETSPlugout and GreenstoneMETSPlugout, rather than this being controlled through a -version option for METSPlugout.

File:
1 edited

Legend:

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

    r14925 r14935  
    5050use plugin;
    5151use plugout;
     52use manifest;
    5253use util;
    5354use scriptutil;
    5455use FileHandle;
    55 use gsprintf;
     56use gsprintf 'gsprintf';
    5657use printusage;
    5758use parse2;
     
    6162    [ { 'name' => "hash",
    6263        'desc' => "{import.OIDtype.hash}" },
     64      { 'name' => "assigned",
     65        'desc' => "{import.OIDtype.assigned}" },
    6366      { 'name' => "incremental",
    6467        'desc' => "{import.OIDtype.incremental}" },
    65       { 'name' => "assigned",
    66         'desc' => "{import.OIDtype.assigned}" },
    6768      { 'name' => "dirname",
    6869        'desc' => "{import.OIDtype.dirname}" } ];
     
    7273    [ { 'name' => "DSpace",
    7374        'desc' => "{export.saveas.DSpace}" },
    74       { 'name' => "METS",
    75         'desc' => "{export.saveas.METS}"},
     75      { 'name' => "GreenstoneMETS",
     76        'desc' => "{export.saveas.GreenstoneMETS}"},
     77      { 'name' => "FedoraMETS",
     78        'desc' => "{export.saveas.FedoraMETS}"},
    7679      { 'name' => "GA",
    7780        'desc' => "{export.saveas.GA}"},
     
    8992# modegli: The lowest detail mode this argument is visible at in GLI
    9093
    91 my $saveas_argument =       
     94my $saveas_argument =
    9295      { 'name' => "saveas",
    9396    'desc' => "{export.saveas}",
     
    102105    [
    103106      $saveas_argument,
    104       { 'name' => "saveas_version",
    105     'desc' => "{export.saveas_version}",
    106     'type' => "string",
    107     'reqd' => "no",
    108        'deft' => "greenstone" },
    109107      { 'name' => "exportdir",
    110108    'desc' => "{export.exportdir}",
     
    128126    # parsearg left "" as default
    129127    #'deft' => &util::filename_cat ($ENV{'GSDLHOME'}, "collect"),
    130         'reqd' => "no",
     128    'deft' => "",
     129    'reqd' => "no",
     130    'hiddengli' => "yes" },
     131      { 'name' => "manifest",
     132    'desc' => "{import.manifest}",
     133    'type' => "string",
     134    'deft' => "",
     135    'reqd' => "no",
    131136        'hiddengli' => "yes" },
    132137      { 'name' => "listall",
     
    145150    'reqd' => "no",
    146151        'modegli' => "4" },
     152      { 'name' => "incremental",
     153    'desc' => "{import.incremental}",
     154    'type' => "flag",
     155    'hiddengli' => "yes" },
    147156      { 'name' => "keepold",
    148157    'desc' => "{export.keepold}",
    149158    'type' => "flag",
    150159    'reqd' => "no",
    151         'hiddengli' => "yes" },
     160    'hiddengli' => "yes" },
    152161      { 'name' => "removeold",
    153162    'desc' => "{export.removeold}",
     
    207216    'reqd' => "no",
    208217        'hiddengli' => "no" },
     218      { 'name' => "fedora_namespace",
     219    'desc' => "{FedoraMETSPlugout.fedora_namespace}",
     220    'type' => "string",
     221    'deft' => "greenstone",
     222    'reqd' => "no",
     223        'hiddengli' => "no" },
    209224      { 'name' => "mapping_file",
    210225    'desc' => "{MARCXMLPlugout.mapping_file}",
     
    244259                'args' => [ $saveas_argument ] };
    245260
    246 sub gsprintf
     261#sub gsprintf
     262#{
     263#    return &gsprintf::gsprintf(@_);
     264#}
     265
     266
     267sub store_collectionmeta
    247268{
    248     return &gsprintf::gsprintf(@_);
     269    my ($collectionmeta,$field,$doc_obj) = @_;
     270
     271    my $section = $doc_obj->get_top_section();
     272
     273    my $field_hash = $collectionmeta->{$field};
     274
     275    foreach my $k (keys %$field_hash)
     276    {
     277    my $val = $field_hash->{$k};
     278
     279
     280### print STDERR "*** $k = $field_hash->{$k}\n";
     281
     282    my $md_label = "ex.$field";
     283
     284
     285    if ($k =~ m/^\[l=(.*?)\]$/)
     286    {
     287
     288        my $md_suffix = $1;
     289        $md_label .= "^$md_suffix";
     290    }
     291
     292
     293    $doc_obj->add_utf8_metadata($section,$md_label, $val);
     294   
     295    if (($md_label eq "ex.collectionname^en") || ($md_label eq "ex.collectionname"))
     296    {
     297        $doc_obj->add_utf8_metadata($section,"dc.Title", $val);
     298    }
     299
     300    }
    249301}
    250302
     
    254306sub main {
    255307    # params
    256     my ($language, $verbosity, $importdir, $exportdir, $site, $keepold, $listall,
    257     $removeold, $saveas, $saveas_version, $debug, $OIDtype, $OIDmetadata,
    258     $maxdocs, $statsfile, $xsltfile, $mapping_file, $out, $faillog, $gs_mode, $collectcfg,
    259     $collectdir, $gli,$xslt_mets,$xslt_txt,$group_marc);
     308    my ($language, $verbosity, $debug,
     309    $importdir, $manifest, $incremental, $keepold,
     310    $exportdir, $site, $listall,
     311    $removeold, $saveas,
     312    $OIDtype, $OIDmetadata,
     313    $out, $faillog, $collectdir, $gli,
     314    $gs_mode, $collectcfg,
     315    $maxdocs, $statsfile,
     316    $mapping_file,
     317    $xsltfile,
     318    $xslt_mets, $xslt_txt, $fedora_namespace, $group_marc);
     319
    260320    my $xml = 0;
    261321   
    262322    # other vars
    263     my ($configfilename, $collection, $export_info_filename, $export_info, $processor, $pluginfo);
     323    my ($configfilename, $collection,
     324    $export_info_filename, $export_info,
     325    $processor, $pluginfo);
     326
    264327    my $service = "export";
    265328
     
    341404    eval {
    342405        # get and check the collection name
    343         print STDERR "**** site = $site\n";
    344406        if (($collection = &colcfg::use_collection($site, $collect_name, $collectdir)) eq "") {
    345407        &PrintUsage::print_txt_usage($options, "{export.params}");
     
    372434        my $plugins = [];
    373435        my @global_opts = ();
    374        
     436
    375437        # Read in the collection configuration file.
    376438        ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
    377        
     439
    378440        if ($gs_mode eq "gs2") {
    379441        $collectcfg = &colcfg::read_collect_cfg ($configfilename);
     
    381443        $collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
    382444        }
     445
     446        if (defined $collectcfg->{'importdir'} && $importdir eq "") {
     447        $importdir = $collectcfg->{'importdir'};
     448        }
     449        if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
     450        $exportdir = $collectcfg->{'exportdir'};
     451        }
     452
     453        # fill in the default import and export directories if none
     454        # were supplied, turn all \ into / and remove trailing /
     455        $importdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "import") if $importdir eq "";
     456        $importdir =~ s/[\\\/]+/\//g;
     457        $importdir =~ s/\/$//;
     458        if (!-e $importdir) {
     459        &gsprintf($out, "{import.no_import_dir}\n\n", $importdir);
     460        die "\n";
     461        }
     462
     463        $exportdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "export") if $exportdir eq "";
     464        $exportdir =~ s/[\\\/]+/\//g;
     465        $exportdir =~ s/\/$//;
    383466
    384467        if (defined $collectcfg->{'plugin'}) {
     
    392475            $verbosity = 2; # the default
    393476        }
    394         }
    395         if (defined $collectcfg->{'importdir'} && $importdir eq "") {
    396         $importdir = $collectcfg->{'importdir'};
    397         }
    398         if (defined $collectcfg->{'exportdir'} && $exportdir eq "") {
    399         $exportdir = $collectcfg->{'exportdir'};
    400477        }
    401478
     
    476553        if ($saveas eq "DSpace"){
    477554        $export_info_filename = &util::filename_cat ($exportdir, "contents");
    478         } elsif ($saveas eq "METS" || $saveas eq "GA" || $saveas eq "MARC" ) {
     555        } elsif ($saveas =~ m/^.*METS$/ || $saveas eq "GA" || $saveas eq "MARC" ) {
    479556        $export_info_filename = &util::filename_cat ($exportdir, "export.inf");
    480557        }
     
    488565        }
    489566        else{
    490         if ($saveas !~ /^(GA|METS|DSpace|MARCXML)$/) {
     567        if ($saveas !~ /^(GA|.*METS|DSpace|MARCXML)$/) {
    491568            push @$plugout,"GAPlugout";
    492569        }
     
    505582        push @$plugout,("-output_handle",$out) if (defined $out);
    506583        push @$plugout,("-xslt_file",$xsltfile) if (defined $xsltfile);
    507         push @$plugout,("-group") if ($group_marc && $plugout_name =~ /^MARCXMLPlugout$/);
    508         push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $plugout_name =~ /^MARCXMLPlugout$/);
    509         push @$plugout,("-saveas_version",$saveas_version) if (defined $saveas_version && $plugout_name =~ /^METSPlugout$/);
    510         push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $plugout_name =~ /^METSPlugout$/);
    511         push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $plugout_name =~ /^METSPlugout$/);
     584        push @$plugout,("-group") if ($group_marc && $plugout_name =~ m/^MARCXMLPlugout$/);
     585        push @$plugout,("-mapping_file",$mapping_file) if (defined $mapping_file && $plugout_name =~ m/^MARCXMLPlugout$/);
     586        push @$plugout,("-xslt_mets",$xslt_mets) if (defined $xslt_mets && $plugout_name =~ m/^.*METSPlugout$/);
     587        push @$plugout,("-xslt_txt",$xslt_txt) if (defined $xslt_txt && $plugout_name =~ m/^.*METSPlugout$/);
     588        push @$plugout,("-fedora_namespace",$fedora_namespace) if (defined $fedora_namespace && $plugout_name eq "FedoraMETSPlugout");
     589
    512590        $processor = &plugout::load_plugout($plugout);   
    513591       
     
    521599        # process the import directory
    522600        &plugin::read ($pluginfo, $importdir, "", {}, $processor, $maxdocs,0, $gli);
     601
     602        if ($saveas eq "FedoraMETS")
     603        {
     604        # create collection "doc obj" for Fedora that contains
     605        # collection-level metadata
     606
     607        my $doc_obj = new doc($configfilename,"nonindexed_doc");
     608        $doc_obj->set_OID("collection");
     609
     610        my $col_name = undef;
     611        my $col_meta = $collectcfg->{'collectionmeta'};
     612        if (defined $col_meta)
     613        {
     614            store_collectionmeta($col_meta,"collectionname",$doc_obj);
     615            store_collectionmeta($col_meta,"collectioextra",$doc_obj);
     616
     617        }
     618
     619        $processor->process($doc_obj);
     620        }
    523621       
    524622        &plugin::end($pluginfo, $processor);
     
    529627        $processor->close_file_output() if $groupsize > 1;
    530628        $processor->close_group_output() if $processor->is_group();
    531         if ($saveas eq "METS") {
     629        if ($saveas =~ m/^.*METS$/) {
    532630        $export_info->save_info($export_info_filename);
    533631        }
Note: See TracChangeset for help on using the changeset viewer.